Copy link to clipboard
Copied
Hello all, I have this project that will basically work like a slideshow. I am trying to do things the right way and avoid scenes so I am building each slide as a separate mc and then placing them on the main timeline. What I'm trying to do is get the playback head to advance to the next frame on the main timeline once the mc reaches its last frame. I have found code that works but it seems pretty ghetto:
var _root:MovieClip = MovieClip(root)
stage.addEventListener(Event.ENTER_FRAME, text2);
function text2 (myevent:Event):void {
_root.gotoAndStop("slide2");
}
I guess I have two basic questions:
1. What is the proper way to target a frame on the main timeline from within a mc in as3?
2. Does the way I'm building this make sense or is there a better solution?
Thanks for reading!
That code is an accident waiting to happen. An ENTER_FRAME event fires repeatedly, at the frame rate of the file. It does not mean what it sounds like...such as..."when something enters a frame" All you would need in place of that code is to put the following line in the last frame of the mc...
MovieClip(root).gotoAndStop("slide2");
Since you asked about "proper"... children should not talk back to their parent and tell them what to do. The good news is they should be independent and only worr
...Copy link to clipboard
Copied
That code is an accident waiting to happen. An ENTER_FRAME event fires repeatedly, at the frame rate of the file. It does not mean what it sounds like...such as..."when something enters a frame" All you would need in place of that code is to put the following line in the last frame of the mc...
MovieClip(root).gotoAndStop("slide2");
Since you asked about "proper"... children should not talk back to their parent and tell them what to do. The good news is they should be independent and only worry about doing what they do. It's up to the parent to keep an eye on the children if they are so inclined. The only thing the child should do is let the world know when they are done doing it. This is done by dispatching an event.
So what you do is set up the child to dispatch an event to indicate they are done doing what they do (in the last frame in your case).
dispatchEvent(new Event("imDone"));
and set up a listener for that child object in the parent timeline for the parent to listen for that event...
childName.addEventListener("imDone", eventHandler);
function eventHandler(event:Event):void {
gotoAndStop("slide2");
}
Copy link to clipboard
Copied
Ned, you're a genious!
I learned more about flash from your post than I did in four hours digging through forums. I owe ya a steak dinner.
Copy link to clipboard
Copied
Medium rare works well for me.
Copy link to clipboard
Copied
Ok follow up question. I made a play/pause button for this project and I have managed to get it to target either the main timeline or a nested MC. The problem is with the code I have is that the button will only work for one MC at a time. This means I will need a separate play/pause button for each individual slide. Is there some way to make a button that globally starts and stops any MC without effecting the main timeline?
Here is the code I am using now:
stop();
pause_btn.addEventListener(MouseEvent.CLICK, stopplaying);
function stopplaying(event:MouseEvent):void {
MovieClip(parent).green.stop();
gotoAndStop(2);
}
Thanks for all your help!
Copy link to clipboard
Copied
One way would be to have whatever movieclip is playing assign itself to a variable when it starts playing and use that variable to target the movievlip in the event handler function instead of a particular instance.
If you have new questions you should start new postings... postings with 0 replies draw attention.
Copy link to clipboard
Copied
How would I write that? I'm a little confused because I don't know how to deal with two event listeners. Here is the code I have that is obviously wrong:
stop();
addEventListener("imHere");
play_btn.addEventListener(MouseEvent.CLICK, stopplaying);
function stopplaying(event:MouseEvent):void {
"imHere".stop();
gotoAndStop(2);
}
I hear you on that double post thing - I didn't want to clutter the forum with my simple questions. Thanks again for all your help and sorry for the dumb questions - I'm far from a developer.