开发者

actionscript error?

I have a problem, this works then at the " and" it dies and gives me an error

TypeError: Error #1009: Cannot access a property or method of a null object reference. at Untitled_fla::MainTimeline/frameLooper() at flash.utils::Timer/_timerDispatch() at flash.utils::Timer/tick()

CODE

var string:String = "Welcome to PuppetWeb Inc\nMy name is Steve and I will be your host for this presentation!\n...\nOkay I think it is ready, let's go!";
var myArray:Array = string.split("");
var timer : Timer = new Timer (100, myArray.length);
timer.ad开发者_开发知识库dEventListener (TimerEvent.TIMER, frameLooper);
timer.start();

function frameLooper(event:Event):void {
    if(myArray.length > 0) {
        text1.appendText(myArray.shift());
    }else{
        removeEventListener(Event.ENTER_FRAME, frameLooper);
    }
}

It works for the start and then just dies at and, and then it shows that error about 50 times and restarts.

Any help?


I assume this is code written on a keyframe in the timeline, so my guess would be that your textfield goes away for some reason, most likely a keyframe animation of some kind.

It's also somewhat odd that you are removing an Event.ENTER_FRAME listener when the array is empty and not the TimerEvent.TIMER


At the end, you're trying to remove the listener from an implicit "this". Your statement is equivalent to:

this.removeEventListener(Event.ENTER_FRAME, frameLooper);

But "this" is a reference to the main timeline (if this is a frame script on the main timeline) or a reference to the instance that contains this code. It's not a reference to the Timer instance, which is what you need:

event.target.removeEventListener(TimerEvent.TIMER, frameLooper);


Why not use string.charAt()?

var string:String = "Welcome to PuppetWeb Inc\nMy name is Steve and I will be your host for this presentation!\n...\nOkay I think it is ready, let's go!";
var timer : Timer = new Timer (100, string.length);
timer.addEventListener (TimerEvent.TIMER, frameLooper);
timer.start();

function frameLooper(event:TimerEvent):void {
    text1.appendText(string.charAt (event.target.currentCount-1);
}


Among all the other issues Stated in the other posts you are not stopping the time.
Dont forget timer.stop( );

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜