R – When a SWF is loaded into another. Can the main SWF read the loaded one to retrieve its contents and modify them

actionscript-3flash

Give this scenario:

  • I have a cool graphic in Illustrator or Flash.
  • The graphic represents a figure, with various elements inside, shapes, lines, gradients, etc.
  • I export it to a swf file and I can view my nice graphic if I open it.
  • I have a (pure) as3 application, which loads swfs.

Then…

  • Can I manipulate the contents of the loaded swf. For example: Moving its contents, changing some elements inside, duplicating them. Deforming them with the transform matrix and things like that?
  • Can I, at least, read the contents and replicate them (the graphic data) inside the main application.

As far as I've been researching, I can only import the swf and use it as a whole display object, without any children, and I cannot modify it.

I want to, somehow, use the graphic information of the external swf to allow the main application deform it or use it to make new versions of the graphic.

Best Answer

No, sadly you can't retrieve or change compiled Graphics elements in detail, you can only use them as DisplayObjects and transform them through their public properties (scale, rotation, transform, etc...). There is way of programmaticaly retrieve a single path coordinates by setting it as the "guide" of an object in the Flash IDE and within an onEnterFrame retrieve the object's position, but as you can imagine, its quite dirty.

You can replicate the clips by either setting them as classes within the loaded SWF (In Flash IDE: library>symbol>properties>export for AS) or using BitmapData to draw them as you please from the main movie.

Another solution would be to use a more open format, like SVG or FXG, but it can get quite complicated...