views:

584

answers:

3

I've embedded a SWF into a class using this syntax above my class definition:

[Embed (source='/../assets/MyMovieClips.swf', symbol='SpecialMovieClip')]
public class SpecialMovieClip extends MovieClip

The MovieClip asset seems linked with my class okay, and instantiates along with it, and is visible, but:

  • I can't access instances placed on stage within that clip.
  • The timeline scripting seems non-functional.

Is this the drawback of embedding SWF files at compile-time with the Flex SDK? So, maybe I should just go back to compiling with the Flash IDE if I want timeline scripting or instances positioned on-stage?

A: 

I've admittedly never attempted to directly instantiate an embedded swf as a MovieClip. I've normally used SWFLoader (and that actually may solve this, by some bizarre means), but here are some things you may want to try:

// Iterate through the descendants of SpecialMovieClip...  Sometimes there will
// be an additional layer or two which will cause problems.
var org:DisplayObjectContainer = new SpecialMovieClip();

while( org )
{
    trace( org.name + " is " + getQualifiedClassName( org ) );
    org = org.getChildAt( 0 ) as DisplayObjectContainer;
}

As to the script on the main timeline of the embedded asset, I would recommend the following code on its root (just to ensure that the code is functional at all):

setInterval( dispatchEvent, 1000, new Event( "IAMTESTING", true, false ) );

then, before calling addChild, place this on the DisplayObjectContainer which will hold your SpecialMovieClip:

addEventListener( "IAMTESTING", trace ).

you may simply have an issue where the code is attempting to fire, but it is failing because it needs to actually be on stage to do so.

Let me know if this helps at all...

Christopher W. Allen-Poole
+1  A: 

From the docs: (scroll down to "Embedding SWF Symbols")

If the SWF file contains any ActionScript code, Flex prints a warning during compilation and then strips out the ActionScript from the embed symbol. This means that you can only embed the symbol itself.

Depending on what you want to do, I think you'd be better off embedding the entire SWF, or loading things in at runtime.

Incidentally, regarding not being able to access stuff within the embedded symbol, did you make sure that the target SWF is AS3? If you're embedding (or loading) AS2 content, then interoperability is only allowed through LocalConnection. This is also covered on the doc page I linked.

fenomas
+2  A: 
  1. if you embed with the [Embed ] tag all scripts will be stripped from you symbol. But you can add script to frames with MovieClip.addFrameScript():

    public function SpecialMovieClip(){

    addFrameScript(4,myfunc)

    }

    private function myfunc(){

    stop()

    }

  2. i think you can only access the symbols inside a movieClip with movieClip.GetChildAt()

thtzhthz