AS3 - gotoAndStop with immediate action

后端 未结 2 530
青春惊慌失措
青春惊慌失措 2021-01-19 01:55

I\'m moving from AS2 to AS3 and probably as many ppl before found this incompatibility:

I used quite often code like:

gotoAndStop(5);
trace(box); //w         


        
2条回答
  •  面向向阳花
    2021-01-19 02:46

    no easy way to do that.

    what you need to do is

    • setup a listener for when the frame renders

    • tell it to go to the said frame(5)

    • force the rendering to happen ASAP stage.invalidate

    .

    One of the top reasons to stay with as2. Not saying as2 is better, just better at a few things and this is one of them. My opinion on this is that as3 wasn't really meant to handle timelines very well.

    with as2 you do

    gotoAndStop(5);
    trace(box);
    

    With as3 you need to wait for the timeline to render.

    stage.addEventListener(Event.RENDER, onRenderStage);
    protected function onRenderStage(ev:Event):void {
        trace(this['box']);
    }
    gotoAndStop(5);
    stage.invalidate();
    

    I used to have different assets in different frames of one MovieMlip in my as2 days, but to do that in AS3 is too complicated to enjoy any of the benefits. So while this will work, I'd recommend looking into a different solution altogether. Or stick to as2.

提交回复
热议问题