0

I've been successful at loading an external SWF into my primary SWF, and I've been able to access the external SWF's classes because I loaded it into the same ApplicationDomain.

var exClass:Class = myAppDomain.getDefinition(my.stuff.com::externalClass) as Class;

But now if I want to instantiate exClass, do I have to use * as the type? In this case, exClass extends DisplayObject, so I have to do this to make it work:

var myInstanceExClass:* = new exClass(arg1,arg2);
addChild(myInstanceExClass);
myInstanceExClass.method1();

Is that the way you're supposed to do it? It seems I have to use * as the type because I'm not doing an import my.stuff.com.externalClass, which I do not want to do. Importing that class would defeat the purpose of loading the external SWF.

BladePoint
  • 632
  • 5
  • 16
  • 1
    Well, yes. Unless you can declare it as **MovieClip** which is dynamic class so it lets you address fields and methods not specifically declared, the * type is the one that allows you to pass this object to function arguments without raising the typecasting-relating errors, as well as to address any members of such an object without restrictions. So, what's the problem? – Organis Sep 10 '19 at 03:59
  • It just feels weird instantiating stuff using * for type, especially when the actual type is available, albeit coming from an external SWF. But if that's the only way to do it, then that's the only way to do it. – BladePoint Sep 10 '19 at 17:36
  • Weeeeell, you can actually include SWC as an external library, so you can benefit from parsing and type-checking all the included classes in your code without actually compiling them into the app. – Organis Sep 10 '19 at 18:39
  • However, I stopped using loadable modules architecture back in AS2. Too much trouble for dubious benefits. Now I always put all the code into a single app, which loads code-less SWF libraries of assets. Thus I keep the main application small and fast to build, with no regard to how much my whole application actually weights, assets included. – Organis Sep 10 '19 at 18:42
  • Do you mean including SWCs at compile time? My main SWF downloads external libraries from the Internet then loads them, so that wouldn't work for me. Or is there a way to download an SWC, unzip it, load the SWF and parse the xml to get the classes, and avoid the * type thing? – BladePoint Sep 11 '19 at 17:14
  • There are three (I think) variants **HOW** to include a library into the project: a) internal, b) runtime-shared and c) external. The latter means you can refer classes and their fields, benefit from auto-complete and parsing, but these classes and related visual resources are not embedded into your app upon building. – Organis Sep 11 '19 at 18:58
  • Yes, I've been attempting the external method with some success as I mention in my original post, but with limitations because I have to instantiate as * type. I was hoping there was some way to load an external library and use its classes exactly the same way as if I had imported it at compile time. – BladePoint Sep 11 '19 at 19:25

0 Answers0