flash-as3 code execution order: accessing a flash

2019-09-02 06:53发布

问题:

this is a follow up question to this question

i have never actually got the flash-actionscript code execution order.

in flash pro i have an instance of a moveiclip on stage in frame one named tree1 and on frame 3 i have on the stage tree3.

in the document class i have this code:

stop();
var scaleFactor:Number = tree1.scaleX;
gotoAndStop(3);
tree3.scaleX = scaleFactor;

while this works when testing on the desktop, this app will go mobile at the end

is this the correct way to go or should i register for a frameComplete event before accessing instances on a certain frame

回答1:

So, just dont use the Document Class cause you will need to declare all the scenes from the beginning and will be complicate to manage each scene.

I suggest you to instance a simple MovieClip linked with his own class like the example SceneTree, put it on each Keyframe. You will have more control when you are entering or exiting each frame.

package  {

    import flash.display.MovieClip;
    import flash.events.Event;


    public class SceneTree extends MovieClip {


        public function SceneTree() {
            super();
            this.addEventListener(Event.ADDED_TO_STAGE, Init);
            this.addEventListener(Event.REMOVED_FROM_STAGE, removed);
        }
        protected function Init (event:Event):void{
            trace("added")
        }
        protected function removed (event:Event):void{
            trace("removed")
        }

    }

}


回答2:

waiting for Event.FRAME_CONSTRUCTED is the correct way whenever accessing assets on a timeline

it insures all assets have been created