views:

202

answers:

2

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.

A: 

You can access loaded SWF's methods and properties if both are AVM2 movies.

var loader:Loader = new Loader();
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onLoadComplete);
private function onLoadComplete(e:Event):void
{
  var content:Object = LoaderInfo(e.target).content;
  //assuming there is a public someMethod() defined in 
  //the document class of the loaded SWF, you can call it as:
  content.someMethod();
  //you can access any property you wish
  content.someObject.graphics.beginFill(0x00ff00);
  content.someObject.graphics.drawCircle(10, 10, 10);
  content.someObject.graphics.endFill();
}
Amarghosh
Thanks for pointing the AVM compatibility, is not a problem in my application, but it's a good thing to know.Well, about the use of loader, I'm already using it to retrieve contents. The key of my question is if I can retrieve to my main the imported objects information. Things like color, gradient, stroke, something I could use with the graphics class.For example, if I laod a swf with a rectangle inside, with a stroke of 2px and a linear gradient fill top bottom, I want to modify that and know what colors and sizes are in use in the graphics instance of the imported swf objects
yizzreel
yes you can. `graphics` is just another public property of the loaded object - you can access it. check my update to see how to draw a green circle on the loaded SWF.
Amarghosh
You cannot modify the drawings done with CS3, though
Amarghosh
+1  A: 

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...

Cay
SVG was exactly I want to avoid by using external swfs, but I'm afraid there's no other way (at least right now). Thanks for your answer.
yizzreel