Reputation:
Is it possible to load an ActionScript 3 SWF and interact with it, for example by replacing some of its functions or editing variables? Similar to how it's possible in .NET using reflection and code generation.
I'm looking to add an extra layer of functionality over an existing 3rd-party AS3 app.
Upvotes: 1
Views: 1327
Reputation: 243
Aspose.Flash can help you with editing variables since it has support for the action script byte code decompilation, however it's not free and can't emit new functions unless you use an external as3 compiler(e.g. the one from Adobe that's free and open source)
Upvotes: 0
Reputation: 51837
Well, you could could control the things(clips and other swf components) that are publicly available by digging in through the hierarchy of objects, just basic stuff. The other choice is you could decompile the loaded swf at runtime. This library sounds pretty interesting for that task.
Upvotes: 0
Reputation: 59451
If you are loading it to another AS3 SWF, yes, you can access the public properties of the loaded SWF. You cannot replace functions - you can call functions, public ones, that is.
var ldr:Loader = new Loader();
ldr.contentLoaderInfo.addEventListener(Event.COMPLETE, onLoad);
ldr.load(new URLRequest("filename.swf"));
private function onLoad(e:Event):void
{
var swf:Object = LoaderInfo(e.target).content;
swf.somePublicVar = newValue;
swf.somePublicObject.publicMethod();
swf.getChildAt(0).x = 30;
//assuming there is a sprite at index 1
var child:Sprite = Sprite(swf.getChildAt(1));
child.graphics.lineStyle(1);
child.graphics.drawCircle(10, 10, 10);
}
If you are loading 3rd party SWF from another domain (instead of copying it to your domain and loading it from there), the following rule apply
Security.allowInsecureDomain()
method in the loaded content file.Which in short means that unless the SWF creator has explicitly allowed it to be modified from your domain, you cannot modify it by loading it remotely. This doesn't apply if you can get the SWF copied to your domain.
Upvotes: 7