04 November 2008

Accessing Scenes in loaded SWFs (AS3)

Ok, ok, I can hear you now, "don't use scenes, silly boy!", but really, they're the best compromise to allow animators to freely draw avatars and allow me to control the avatar orientation with each scene.

Animators would send me swfs containing scenes named as each avatar orientation (N, S, E, W etc). I would then load these swfs into the game and use the scenes to control the avatars orientation. The problem is I couldn't access any of the scenes I got from the animators swfs. My proof of concept worked perfectly, but when I got the real stuff, it wasn't working!?

If I checked loadedMC.scenes.length, I would get a value of 1 instead of the expected 5, yet it would still cycle through all the scenes, but where were they?

I asked for the fla's and all seemed fine. However there was 1 minor difference: the animators were using Graphic symbols on the timeline in each scene, not MovieClips. I added a blank MovieClip to each scene and hey-presto, the scenes were accessible!

So if you use scenes, make sure you have MovieClip symbols inside them, otherwise you won't be able to access them at run-time.

*** Update ***
Please read comments to this post


marc van der woerd said...

Hi Dan, liked your idea!
It got me thinking;

It looks like Flash dumps the timeline as soon as there is nothing on it, that it can use.

We went from movieclip to something smaller like a sprite, which worked too.

All in all it seems that by putting anything on the timeline, it will make it accessible again.

a small comment in Actionscript for each scene therefore should do the trick without impacting the overall filesize of your movie.

This is all theory based, let me know if it works.


hasta luego,

Dan Lavender said...

Hi Marc,

Spot on. It's a really weird behaviour. In fact, all I need to do is put a comment on the 1st frame of the 1st scene and all other scenes are accessible.