我有一段代码,我遇到了问题,似乎即使我告诉它这样做,事件监听器也没有被删除,导致第2帧出现1009错误。
以下是代码:
stop();
import flash.events.Event;
var loaded:Number
var total:Number;
var percent1:Number;
var percent2;
addEventListener(Event.ENTER_FRAME, enterFrameEvent);
function enterFrameEvent(event:Event):void{
loaded = this.loaderInfo.bytesLoaded;
total = this.loaderInfo.bytesTotal;
percent1 = loaded/total;
percent2 = percent1 * 100;
loadingBar.scaleX = percent1;
playButton.alpha = percent1;
if(loaded===total){playButton.alpha = 1};
}
if (loaded === total){removeEventListener(Event.ENTER_FRAME, enterFrameEvent)}
addEventListener(MouseEvent.CLICK, mouseClick);
function mouseClick (event:MouseEvent){
if (playButton.alpha == 1){
removeEventListener(MouseEvent.CLICK, mouseClick);
gotoAndPlay(2);
}
答案 0 :(得分:1)
试试..
if (loaded == total){removeEventListener(Event.ENTER_FRAME, enterFrameEvent)}
而不是......
if (loaded === total){removeEventListener(Event.ENTER_FRAME, enterFrameEvent)}
区别是==(相等运算符)和===(严格相等运算符)。希望有效。