4/10/2011

loading in as3

 stop();
//先讓時間軸暫停。
this.addEventListener(Event.ENTER_FRAME, onRootEnterFrame);
//偵聽ENTER_FRAME事件。
function onRootEnterFrame(e:Event):void {
    var _bytesLoaded:int = this.loaderInfo.bytesLoaded;
    //已載入元位組。
    var _bytesTotal:int = this.loaderInfo.bytesTotal;
    //總檔案大小元位組。
    var _percentage:int = (_bytesLoaded / _bytesTotal * 100);
    //二者相除並乘上一百, 即可得到百分比。
    if (_percentage >= 100) {
        //如果載入的百分比大於等於100, 表示載入完畢。
        this.removeEventListener(Event.ENTER_FRAME, onRootEnterFrame);
        //取消偵聽。
        this.play(); //as here
        //播放時間軸。
    } else {
        percent_txt.text = "LOADING" + _percentage +"%";
    }
}

//注意記得在該場景放一個文字輸入物件並且命名 percent_txt標籤
//原作 奶綠茶

No comments:

Post a Comment