the code you showed is an example of poor coding and should never be used in as1/as2.
in as2, use:
in as3, use:
MovieClip(root).gotoAndPlay(2); // don't use a number as a label and don't start a label with a number
1 person found this helpful
Actionscript 3 does not allow code to be attached directly on objects. This is by design, to force better coding habits.
AS3 also does not use the onClipEvent structure that AS2 did.
If you want to gotoAndPlay(2) when the frame starts, simply place that on the timeline.
And, if you want the root level to do this:
is all you need. No onClipEvent necessary. (It wasn't necessary in AS2 either, rather was a leftover from AS1)
But must you attach it to a movie clip now and not to a frame action? Seems
dumb to have to do that...
MovieClip(root).gotoAndPlay(2); // don't use a number as a label and don't
start a label with a number
Jefferis Peterson, Pres.
Web Design and Marketing
It is not that you are attaching it to a MovieClip, rather that you are directing the MovieClip called "root" (the main timeline) to do something.
The action is still a frame action. It executes as soon as the frame is loaded.
I was coding from memory and haven't used AS in a while, however, neither of
these work for the script. Timeline is still jumping back to frame one,
which has a preloader. I hope that isn't throwing off the frame number...
Anyway, the last MC in the the last frame, when I click on it, it says,
"Current selection cannot have actions applied to it"
And actions applied to the frame are not working either.
Also, any reason you cannot paste code into the actions panel? Every time I
try, even when selected, it pastes onto the stage instead...
Where does "endMC" come into the picture here? Perhaps we need some more explanation as to how the project is built to properly diagnose the issue.
1 person found this helpful
no code in as3 can be attached to an object. attach your code to a frame.
the root must be cast as a MovieClip in as3:
MovieClip(root).gotoAndPlay("frame label or frame number here");
when the playhead enters the frame that contains the line of code above, it will redirect to the main timeline's label or number. if you don't want to direct the main timeline, you must use the correct reference to the movieclip you do want to direct.
Obviously, emails from Outlook are not posting. This is weird. 2 replies below...
I have done exactly as you suggested. I created a keyframe on an empty layer and added this code:
MovieClip(root).gotoAndPlay(75); but it is skipping this code and jumping back to frame 1. This is a simple 9 layer doc with a single scene and a single timeline and 4 symbols (pictures).
I linked the file so you can take a look at it... It is only 732k unzipped. http://www.petersonsales.net/3r/andreynew.fla.zip
Hi Ross, thanks for hanging in there with me.
I have used classic tweens on a symbol to fade out to the last frame using 4 F6 keyframes with duplications of the symbol. Fade in tween. Stay visible for a while, then fade out. I named the last instance of the MC 'endMC' because I couldn't target the clip any other way, but I am not targeting it now. I was trying old AS to set it as a target as one attempt to figure out what was not working.
So, bottom line. Last keyframe has an MC in it with no actions assigned to it, and no targeting of that mc. I was trying to just do a gotoAndPlay on the last frame itself as you suggested as my first attempt to make it work. When that failed to go to the label "restart" or the frame 2 (I did not have the frame number in quotes in my code), it would not work, and I remembered in old AS you had to use On EnterFrame to start the action, or some such nonsense. However, nothing is making it jump back to frame 2.
Should be fairly simple but it isn't working...
Well Guys, I found the problem. It WAS the preloader throwing off the AS3. I don't know if the problem was an AS2 preloader, but I kept getting errors on a #initClip statement. So I got some code for an AS3 preloader and the loop back works.