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

我只是一个虾纸丫 提交于 2019-12-24 20:12:07

问题


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.


回答1:


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




回答2:


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();
}



回答3:


SWF content can be readed by new function added to Flash Player 11.6 and AIR 3.6:

flash.display.Grapics.readGraphicsData()

http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/display/Graphics.html#readGraphicsData%28%29

Similar problem:

How to read data from shape/graphics object



来源:https://stackoverflow.com/questions/1816005/when-a-swf-is-loaded-into-another-can-the-main-swf-read-the-loaded-one-to-retri

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!