views:

492

answers:

2

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 strategy 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??

A: 

A quick and easy (though somewhat dirty) way of doing it...

package {
    public class MyDocumentClass extends MovieClip {
        public static var ROOT:MyDocumentClass;

        public function MyDocumentClass() {
            MyDocumentClass.ROOT = this;
        }
    }
}

Then, after importing MyDocumentClass (if needed - ie. in a different pacakge) call

if (MyDocumentClass.ROOT.animating == false) { }
MyDocumentClass.ROOT.animating = false;
sberry2A
ThanksI placed the first snippet of code at the start of my code on frame1 and tested it --> I get the error 1037:Packages cannot be nested
ss
This code goes into a file called MyDocumentClass.as in the same folder as your FLA file. You'll have to assign it as the document class. Go to the Properties pane when you're on the main stage with nothing selected and enter the class name where it says "Document class".
Selene
That makes more sense --- I've done that, but now I get eror 1017 (def of base class MovieClip nf) and 5000 (the class MyDocClass must subclass flash.display.MC since its is linked to a library symbol of that type)
ss
I'm thinking that if I'm serious about learning AS3 I should redo the code properly rather than patch it up. I think I have time on this job. So I've asked the question in a diff way, see "AS3: load mc’s on button presses and check if mc’s are running".
ss
A: 

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.

Sawrb