开发者

AS3: How do I check and reset variable on the main timeline from inside a movieclip

I'm converting an old AS2 file into AS3 (and trying to learn AS3 at the same time). A movie clip contains a number of different animated sequences and buttons within the application trigger these different sequences. The buttons are functional only when an animation has completed playing.

In AS2, I achieved this with a var called _root.animating which was initially set to "false" and switched to true when the animation played and switched back to false at the end of the anim sequence. The buttons checked this var when clicked. Here is some of the AS2...

_root.animating = false;    //MC code to reset var at end of each sequence:
if (animating == false)...  //btn code to check var

I dont like putting code inside mc's but this worked reliably and got me past the deadline. Now I want to rework the file in AS3 and I think this strateg开发者_如何学Pythony has come back to bite me.

Tried simply changing _root to root or stage -- ooh, if it was that easy. I read something about global classes and Singletons etc but this seems overkill for this sort of thing.

Any suggestions??


Until the time you feel you are ready to mess around with Classes and packages, you can do this for the time being:

//On Stage:

var animating:boolean = true;


//From inside Movieclip on stage:

trace(MovieClip(_parent).animating);

//'Movieclip' is a keyword - do not substitute with the name of the MC on stage

The above will work assuming that the movieclip on the stage from where the root variable is being accessed is just one level below the stage. If it is from a nested Movieclip, than keep adding '_parent.' to the part inside the parantheses until you have successfuly referenced the stage.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜