我为预加载器编写了一个代码,该代码在以框架动作编写时有效。但是后来我决定将所有代码移到类中并对其进行了一些修改。现在它不起作用了。侦听器应该调用的函数没有被调用,并且在这个未被调用的函数中指向参数事件时我开始收到错误。
package {
import flash.display.MovieClip;
import flash.events.Event;
import flash.events.ProgressEvent;
public class Preloader extends MovieClip {
public function Preloader() {
addEventListener(Event.ADDED_TO_STAGE, init);
}
private function init(e:Event):void {
trace("init started");
removeEventListener(Event.ADDED_TO_STAGE, init);
loaderInfo.addEventListener(ProgressEvent.PROGRESS, showProgress);
trace("init completed");
}
private function showProgress(e:Event):void {
trace(loaderInfo.bytesLoaded);
/*info_txt.text = Math.floor(e.bytesLoaded/e.bytesTotal*100) + "%"
if (e.bytesLoaded==e.bytesTotal) {
loaderInfo.removeEventListener(ProgressEvent.PROGRESS, showProgress);
finalizeLoading();
}
/**/
}
private function finalizeLoading():void {
removeChild(info_txt);
var startGame_btn = new StartGame_btn();
addChild(startGame_btn);startGame_btn.x=395;startGame_btn.y=290;
}
}
}
当我取消注释 /*info_txt... 部分时。我明白了:
Access of possibly undefined property bytesLoaded through a reference with static type flash.events:Event.
Access of possibly undefined property bytesTotal through a reference with static type flash.events:Event.
Access of possibly undefined property bytesLoaded through a reference with static type flash.events:Event.
Access of possibly undefined property bytesTotal through a reference with static type flash.events:Event.