| 套件 | flash.events |
| 類別 | public class ProgressEvent |
| 繼承 | ProgressEvent Event Object |
| 子類別 | ModuleEvent, ResourceEvent, RSLEvent, StyleEvent, VideoProgressEvent |
| 語言版本: | ActionScript 3.0 |
| 執行階段版本: | AIR 1.0, Flash Player 9, Flash Lite 4 |
ProgressEvent.PROGRESS 和 ProgressEvent.SOCKET_DATA。此外,在 AIR 中使用 NativeProcess 類別將資料傳送至子處理程序或從子處理程序傳送資料時,就會傳送 ProgressEvent 物件。
相關 API 元素
公用屬性
| 屬性 | 定義自 | ||
|---|---|---|---|
![]() | bubbles : Boolean [唯讀]
指出事件是否為反昇事件。 | Event | |
| bytesLoaded : Number
偵聽程式處理事件時,載入的項目數量或位元組數。 | ProgressEvent | ||
| bytesTotal : Number
如果載入程序成功,將載入的總項目數量或位元組數。 | ProgressEvent | ||
![]() | cancelable : Boolean [唯讀]
指出是否可避免與事件相關聯的行為指令。 | Event | |
![]() | constructor : Object
類別物件的參照或是特定物件實體的建構函數。 | Object | |
![]() | currentTarget : Object [唯讀]
正主動使用事件偵聽程式處理 Event 物件的物件。 | Event | |
![]() | eventPhase : uint [唯讀]
事件流程中的目前階段。 | Event | |
![]() | target : Object [唯讀]
事件目標。 | Event | |
![]() | type : String [唯讀]
事件類型。 | Event | |
公用方法
| 方法 | 定義自 | ||
|---|---|---|---|
ProgressEvent(type:String, bubbles:Boolean = false, cancelable:Boolean = false, bytesLoaded:Number = 0, bytesTotal:Number = 0)
建立包含進度事件相關資訊的 Event 物件。 | ProgressEvent | ||
[覆寫]
建立 ProgressEvent 物件的副本,然後設定每個屬性值以符合原始物件的屬性值。 | ProgressEvent | ||
![]() |
公用程式函數,可用來實作自訂 ActionScript 3.0 Event 類別中的 toString() 方法。 | Event | |
![]() |
指出物件是否有已定義的指定屬性。 | Object | |
![]() |
檢查是否已經對事件呼叫 preventDefault() 方法。 | Event | |
![]() |
指出 Object 類別的實體是否位於指定為參數的物件原型鏈中。 | Object | |
![]() |
如果可以取消事件的預設行為指令,則取消該行為指令。 | Event | |
![]() |
指出指定的屬性是否存在,以及是否可列舉。 | Object | |
![]() |
為迴圈作業設定動態屬性的可用性。 | Object | |
![]() |
避免處理事件流程中,目前節點以及任何後續節點中的任何事件偵聽程式。 | Event | |
![]() |
避免處理接續在事件流程中的目前節點之後,後續節點中的任何事件偵聽程式。 | Event | |
![]() |
傳回代表此物件的字串,根據地區特定慣例進行格式化。 | Object | |
[覆寫]
傳回包含 ProgressEvent 物件所有屬性的字串。 | ProgressEvent | ||
![]() |
會傳回指定之物件的基本值。 | Object | |
公用常數
| 常數 | 定義自 | ||
|---|---|---|---|
| PROGRESS : String = "progress" [靜態]
定義 progress 事件物件的 type 屬性值。 | ProgressEvent | ||
| SOCKET_DATA : String = "socketData" [靜態]
定義 socketData 事件物件的 type 屬性值。 | ProgressEvent | ||
| STANDARD_ERROR_DATA : String = "standardErrorData" [靜態]
定義 standardErrorData 事件物件的 type 屬性值。 | ProgressEvent | ||
| STANDARD_INPUT_PROGRESS : String = "standardInputProgress" [靜態]
定義 standardInputProgress 事件物件的 type 屬性值。 | ProgressEvent | ||
| STANDARD_OUTPUT_DATA : String = "standardOutputData" [靜態]
定義 standardOutputData 事件物件的 type 屬性值。 | ProgressEvent | ||
屬性詳細資訊
bytesLoaded | 屬性 |
bytesTotal | 屬性 |
bytesTotal:Number| 語言版本: | ActionScript 3.0 |
| 執行階段版本: | AIR 1.0, Flash Player 9, Flash Lite 4 |
如果載入程序成功,將載入的總項目數量或位元組數。如果 progress 事件已傳送/附加至 Socket 物件,除非已在建構函式的 bytesTotal 參數中指定值,否則 bytesTotal 將固定為 0。來回傳送的實際位元組數目並未設定,這是由應用程式開發人員決定。
實作
public function get bytesTotal():Number public function set bytesTotal(value:Number):void建構函式詳細資料
ProgressEvent | () | 建構函式 |
public function ProgressEvent(type:String, bubbles:Boolean = false, cancelable:Boolean = false, bytesLoaded:Number = 0, bytesTotal:Number = 0)| 語言版本: | ActionScript 3.0 |
| 執行階段版本: | AIR 1.0, Flash Player 9, Flash Lite 4 |
建立包含進度事件相關資訊的 Event 物件。 Event 物件會當做參數傳遞至事件偵聽程式。
參數type:String — 事件類型。可能的值為:ProgressEvent.PROGRESS、ProgressEvent.SOCKET_DATA、ProgressEvent.STANDARD_ERROR_DATA、ProgressEvent.STANDARD_INPUT_PROGRESS 與 ProgressEvent.STANDARD_OUTPUT_DATA。
| |
bubbles:Boolean (default = false) — 判斷 Event 物件是否參與事件流程的反昇階段。
| |
cancelable:Boolean (default = false) — 判斷是否可以取消 Event 物件。
| |
bytesLoaded:Number (default = 0) — 在偵聽程式處理事件時,載入的項目或位元組數目。
| |
bytesTotal:Number (default = 0) — 如果載入程序成功,將載入的總項目數量或位元組數。
|
方法詳細資訊
clone | () | 方法 |
toString | () | 方法 |
常數詳細資訊
PROGRESS | 常數 |
public static const PROGRESS:String = "progress"| 語言版本: | ActionScript 3.0 |
| 執行階段版本: | AIR 1.0, Flash Player 9, Flash Lite 4 |
定義 progress 事件物件的 type 屬性值。
這個事件具有下列屬性:
| 屬性 | 值 |
|---|---|
bubbles | false |
bytesLoaded | 在偵聽程式處理事件時,載入的項目或位元組數目。 |
bytesTotal | 如果載入程序成功時,最終將載入的項目或位元組總數。 |
cancelable | false;沒有要取消的預設行為指令。 |
currentTarget | 正主動使用事件偵聽程式處理 Event 物件的物件。 |
target | 回報進度的物件。 |
相關 API 元素
SOCKET_DATA | 常數 |
public static const SOCKET_DATA:String = "socketData"| 語言版本: | ActionScript 3.0 |
| 執行階段版本: | AIR 1.0, Flash Player 9, Flash Lite 4 |
定義 socketData 事件物件的 type 屬性值。
這個事件具有下列屬性:
| 屬性 | 值 |
|---|---|
bubbles | false |
cancelable | false;沒有要取消的預設行為指令。 |
currentTarget | 主動處理 Event 的物件。 |
bytesLoaded | 在偵聽程式處理事件時,載入的項目或位元組數目。 |
bytesTotal | 0;socketData 事件物件無法使用此屬性。 |
target | 回報進度的通訊端。 |
相關 API 元素
STANDARD_ERROR_DATA | 常數 |
public static const STANDARD_ERROR_DATA:String = "standardErrorData"| 語言版本: | ActionScript 3.0 |
| 執行階段版本: | AIR 2, Flash Lite 4 |
定義 standardErrorData 事件物件的 type 屬性值。
這個事件具有下列屬性:
| 屬性 | 值 |
|---|---|
bubbles | false |
cancelable | false;沒有要取消的預設行為指令。 |
currentTarget | 主動處理 Event 的物件。 |
bytesLoaded | 因為此事件,NativeProcessObject.error 緩衝的錯誤資料位元組數量。 |
bytesTotal | 0;standardErrorData 事件物件無法使用此屬性。 |
target | 報告錯誤資料的 NativeProcess 物件。 |
相關 API 元素
STANDARD_INPUT_PROGRESS | 常數 |
public static const STANDARD_INPUT_PROGRESS:String = "standardInputProgress"| 語言版本: | ActionScript 3.0 |
| 執行階段版本: | AIR 2, Flash Lite 4 |
定義 standardInputProgress 事件物件的 type 屬性值。
這個事件具有下列屬性:
| 屬性 | 值 |
|---|---|
bubbles | false |
cancelable | false;沒有要取消的預設行為指令。 |
currentTarget | 主動處理 Event 的物件。 |
bytesLoaded | 因為此事件,NativeProcessObject.error 緩衝的錯誤資料位元組數量。 |
bytesTotal | 0;standardInputProgress 事件物件無法使用此屬性。 |
target | 報告錯誤資料的 NativeProcess 物件。 |
相關 API 元素
STANDARD_OUTPUT_DATA | 常數 |
public static const STANDARD_OUTPUT_DATA:String = "standardOutputData"| 語言版本: | ActionScript 3.0 |
| 執行階段版本: | AIR 2, Flash Lite 4 |
定義 standardOutputData 事件物件的 type 屬性值。
這個事件具有下列屬性:
| 屬性 | 值 |
|---|---|
bubbles | false |
cancelable | false;沒有要取消的預設行為指令。 |
currentTarget | 主動處理 Event 的物件。 |
bytesLoaded | 因為此事件,NativeProcessObject.output 緩衝的輸出資料位元組數量。 |
bytesTotal | 0;standardOutputData 事件物件無法使用此屬性。 |
target | 報告輸出資料的 NativeProcess 物件。 |
相關 API 元素
範例 如何使用本範例
ProgressEventExample.as
下列範例使用
ProgressEventExample 類別,說明在檔案下載時如何使用各種不同的事件偵聽程式。 這個範例會執行下列工作:
- 建立
downloadURL和fileName屬性,指出下載檔案的位置和名稱。 - 在
ProgressEventExample建構函式中,會建立一個名為file的新 FileReference 物件,然後將其傳入configureListeners()方法。 - 接著會將
downloadURLandfileName屬性傳入file.download(),以提示下載檔案的位置。 configureListeners()方法會加入七個事件偵聽程式及其相關聯的訂閱者方法:- 如果取消下載檔案的話,就傳送
cancel/cancelHandler()。 - 如果檔案下載程序已完成,就傳送
complete/complereHandler()。 - 如果無法使用或存取要下載的檔案,就傳送
ioError/ioErrorHandler()。 - 當下載作業已開始,就傳送
open/openHandler()。 - 當下載程序開始,以及當下載程序結束時,就傳送
progress/progressHandler()。 - 若本機播放安全性設定與下載檔案的資料存取類型 (本機和網路) 不相符,就傳送
securityError/securityErrorHandler。 - 當下載物件已選取,就傳送
select/selectHandler()。
- 如果取消下載檔案的話,就傳送
注意:
- 您必須將「本機播放安全性」設定為「只存取網路」才能編譯 SWF 檔案。
- 此範例需要名為 SomeFile.pdf 的檔案。
- 雖然這個範例採用了所有 FileReference 物件可使用的事件,但是大部分情況下只需要一個子集。
package {
import flash.display.Sprite;
import flash.events.*;
import flash.net.FileReference;
import flash.net.URLRequest;
public class ProgressEventExample extends Sprite {
private var downloadURL:String = "http://www.[yourDomain].com/SomeFile.pdf";
private var fileName:String = "SomeFile.pdf";
private var file:FileReference;
public function ProgressEventExample() {
var request:URLRequest = new URLRequest(downloadURL);
file = new FileReference();
configureListeners(file);
file.download(request, fileName);
}
private function configureListeners(dispatcher:IEventDispatcher):void {
dispatcher.addEventListener(Event.CANCEL, cancelHandler);
dispatcher.addEventListener(Event.COMPLETE, completeHandler);
dispatcher.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler);
dispatcher.addEventListener(Event.OPEN, openHandler);
dispatcher.addEventListener(ProgressEvent.PROGRESS, progressHandler);
dispatcher.addEventListener(SecurityErrorEvent.SECURITY_ERROR, securityErrorHandler);
dispatcher.addEventListener(Event.SELECT, selectHandler);
}
private function cancelHandler(event:Event):void {
trace("cancelHandler: " + event);
}
private function completeHandler(event:Event):void {
trace("completeHandler: " + event);
}
private function ioErrorHandler(event:IOErrorEvent):void {
trace("ioErrorHandler: " + event);
}
private function openHandler(event:Event):void {
trace("openHandler: " + event);
}
private function progressHandler(event:ProgressEvent):void {
var file:FileReference = FileReference(event.target);
trace("progressHandler: name=" + file.name + " bytesLoaded=" + event.bytesLoaded + " bytesTotal=" + event.bytesTotal);
}
private function securityErrorHandler(event:SecurityErrorEvent):void {
trace("securityErrorHandler: " + event);
}
private function selectHandler(event:Event):void {
var file:FileReference = FileReference(event.target);
trace("selectHandler: name=" + file.name + " URL=" + downloadURL);
}
}
}
Tue Jun 12 2018, 03:47 PM Z
隱藏繼承公用屬性
顯示繼承公用屬性