Lets say I have two swfs A and B, and at runtime, swf A loads swf B, and I wish to share code between them, to minimize file size and download times.
If swf B has some code (say. com.blah.HelloWorld), I tell the compiler to have swf B's source in swf A's classpath, but only do a compile-time link and not actually compile com.blah.HelloWorld into swf A.
This works, and I have tried it, using a the -includes and -externs compiler options.
However, My problem is that I wish to do this the other way. i.e. swf A and B (and potentially swf C) all need com.blah.HelloWorld, but I want com.blah.HelloWorld to be compiled into just swf A, have it as an external reference in swf B ( and potentially C as well.)
I tried doing this using the externs and includes, but I get ReferenceErrors when I do this.
I want to do this without a having a separate rsl, so I can reduce the number of http requests. Is this possible?
You can split your flex application into modules.
Or you can access individual classes from an SWF loaded at runtime using the getDefinition
method of the ApplicationDomain
class:
var loader:Loader = new Loader();
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onLoad);
loader.load(new URLRequest("c.swf"));
//..
private function onLoad(e:Event):void
{
var domain:ApplicationDomain = LoaderInfo(e.target).applicationDomain;
var Type:Class = domain.getDefinition("pack.MyComponent") as Class;
var myBox:Sprite = new Type();
addChild(myBox);
}