Log in

View Full Version : Detecting end of embedded .swf in AS3?



lilyinblue
11-10-2008, 03:58 PM
I have an old flash project that a client wants more stuff tacked on to the end of. Unfortunately, a different developer created the thing and we can't get the source files from him. So, he suggested embedding the original .swf into a new file and then just letting it play through, then adding more when it is finished. My question is this:

1) I'm not actually our flash guru. So, does anyone know a good way in Actionscript 3 to detect when an embedded .swf hits its end so we can advance to the next keyframe automatically? (There's a way built in to the .swf to fast-forward and rewind, so there's no guarantee it'll always take the same amount of time. Else, I'd just set it to wait a certain number of frames/seconds)

2) The .swf in question has looping music at the end. Is that going to be an issue?

Thanks for any advice.

Medyman
11-10-2008, 05:19 PM
I'm not actually our flash guru. So, does anyone know a good way in Actionscript 3 to detect when an embedded .swf hits its end so we can advance to the next keyframe automatically? (There's a way built in to the .swf to fast-forward and rewind, so there's no guarantee it'll always take the same amount of time. Else, I'd just set it to wait a certain number of frames/seconds)

The MovieClip class has two properties that would be helpful here -- framesLoaded and currentFrame. Theoretically speaking, you should be able to do something like this:

if (mc1.currentFrame == mc1.totalFrames) {
trace("We're at the end, folks.");
}

More information: Adobe LiveDocs (http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/display/MovieClip.html#totalFrames)


The .swf in question has looping music at the end. Is that going to be an issue?
Depends on how the audio is looped. If it's frame dependent, then yes it will be a problem. If it's not, then it shouldn't be. I'd suggest removing the audio (actually, you'll just be able to mute it) from the embedded SWF and adding it to the container SWF. That way, it'll be seamless. Otherwise, you'll probably have a bit of a rough seam when the old SWF ends and the new one begins.

BLiZZaRD
11-11-2008, 02:36 PM
The only problem with Medy's theory (which will work and you could even trace to have the file tell you frame number or label, etc..) is you would have to know the MC's name.

If the original files were paid for then you should be able to get the .fla's from the original developer, or if he is just unreachable and the file is legit, you could always decompile it. :p

Medyman
11-11-2008, 05:08 PM
The only problem with Medy's theory (which will work and you could even trace to have the file tell you frame number or label, etc..) is you would have to know the MC's name.

No you wouldn't. AS3 allows you to traverse the timeline and use object references. You might be able to do it in AS2. I'm not sure as I've never had reason to try it.

In AS3, though, you can do call the object at the top-most layer of the included MC like this (container would the MC that I load the external SWF into);


container.getChildAtIndex(0)
It does require some prior knowledge of the embedded SWF. You could figure all of that out with some trial and error, though.

BLiZZaRD
11-11-2008, 05:14 PM
And what if MC in question didn't have linkage enabled, or an instance name (unlikely I know, but it could happen) ?

Medyman
11-11-2008, 05:20 PM
And what if MC in question didn't have linkage enabled, or an instance name (unlikely I know, but it could happen) ?

It doesn't matter. You're accessing the embedded timeline directly (more specifically, display list). As long as you can see those MC's, a reference to that object is available through the display list.

BLiZZaRD
11-11-2008, 05:26 PM
interesting. :D

jumpropek
11-20-2008, 11:40 PM
Hi I have a similar problem.
I have no way to detect which movie is playing on stage so that when I click on Btn2 it displays Movie2 while Movie1 is still playing in the background stacked behind Movie2.

I have 8 buttons with 8 corresponding movies.
On Btn1 click, play Movie1,
on Btn2 click, play Movie2,
on Btn3 click, play Movie3,

problem is I don't know how to detect which movie is currently playing to
tell it to play current movie out to targeted movie...
HELP would be greatly appreciated.