Flash Actionscript 3.0 MovieClips and GotoFrames and listeners

Doh! It was neat with Actionscript 2.0 but not so in 3.0. Again the same old dirty tricks.

I had an issue with a particular movie clip containing two frames. A particular layer had a small close button movieclip available in frame 1 but not in frame 2. I.e. frame 2 had an empty key frame.

When I initiate a gotoAndStop(2) from the AS file, the graphic does appears but the listeners just disappear. And in some occasions the graphic itself does not appear.

AS 2.0 did not have such issues. I presume this is because of the reason that the whole chunk of information of a movie clip was preloaded. And hence everything remained in the memory. But in AS 3.0 graphics are loaded and initiated frame by frame. I came across an document from Adobe which said that listeners would be made available only if the objects in the frame the pointer moves to completely loads. And to do this we need to listen to the RENDER event. And then proceed with adding any listeners.

Something like this...

myButton.addEventListener(Event.RENDER,triggerButtonInFrameIsNowLoaded);

So you do a gotoAndStop(2) and then add this listener shown above. And when triggerButtonInFrameIsNowLoaded is invoked, you add the required listeners to the movieclips.

Phew! So much for a simple job. I hope Adobe tries to simplify this. And yes! I ended up having all graphics available in frame 1 and making them visible as and when needed.

Also the RENDER even tends to flicker the clip in the browser. It works fine and fast when played in the stand alone flash player. But not so when run in the browser :-(

Comments

Popular posts from this blog

Authoritative Server - MMO

Code dependencies