This is a very short line of Actionscript 3, but its one that I’ve had copied to Stickie on my Desktop forever, so in the interest of cleaning up some, I’ll post it here on the blog in the Code Tips category. I think I’ve memorized at least this much AS3 now too =)
Here it is (queue drumroll) …
Booyeah! Big font…. ok lets explain how this is used. Suppose the instance name the_mc refers to a movieclip on the main timeline. That line of code is being run from inside of another movieclip clip on the timeline (which doesn’t even need to have an instance name). So that nameless movieclip is just referring back to the main timeline with MovieClip(parent). then finding the_mc and telling it to go to frame 2 within its timeline. You can download an example file here…. parent_example_in_as3.zip . Of course you aren’t limited to just using gotoAndStop(2); at the end, you can change the movieclip’s x, y, scaling, etc, etc, using the usual Actionscript 3 code for that.
Also if you were trying to do the same thing inside of a moviclip inside of another movieclip, you’d use…
Or you can skip using the_mc altogether and just get back to the main timeline and tell it where to go with those gotoAndStop statements.
In Actionscript 2 we could have done the same thing by writing…
or even lazier by just using
And if you need more Actionscript 3 training, here’s one source.