Copy link to clipboard
Copied
Hi,
My flash application has lots of resources which will change all the time. In order to keep the the user from having to download my main .swf file over and over again, and in order to keep the main file's size low, I would like to put the resources into separate .swf files and load them dynamically from a url using a Loader.
Once downloaded I would like to extract the classes that are in the resource swf and use them in the main swf. Can anyone share some code for doing this? Note that I am not just interested in using a symbol from the resource swf. I would like to use a class, with all of its methods and everything, and my main swf does not contain the class definition. Only the resource swf does.
Thanks!!
1 Correct answer

This is a great question for flash programming.
And when you know the answer to this, you are likely to use it on daily basis like the top level programmers of an agency.
ApplicationDomain is your answer and the adobe docs has a chapter on this.
ApplicationDomain is where all of your classes will be loaded into and when you use a loader you have the ability to target this with the laoderContext.
AplicationDomain.currentDomain loads all classes into the main app and if your main app already has thes
...
Copy link to clipboard
Copied
This is a great question for flash programming.
And when you know the answer to this, you are likely to use it on daily basis like the top level programmers of an agency.
ApplicationDomain is your answer and the adobe docs has a chapter on this.
ApplicationDomain is where all of your classes will be loaded into and when you use a loader you have the ability to target this with the laoderContext.
AplicationDomain.currentDomain loads all classes into the main app and if your main app already has these classes, then the app uses the parents classes
new Application.Domain() specifies a seperate repo of classes that are loaded in so that classes in the main app will not be confused by the classes in a loaded swf. that refer to the same names.
this locks down the communication between the swfs but will use the newer updated classes on the child when a child is loaded in with the same class names as the parents.
new ApplicationDomain(currentDomain) will enclose a new repo with the parent repo of the class definitions.
Copy link to clipboard
Copied
I have one more question about what you have written. I would like to import a class that is a subclass of a class that is already loaded with my main .swf file. So the parent class is already in the current ApplicationDomain. At compile time, I don't know what classes I will be loading from external .swf files, so I want to cast them as the parent class to use them. For example I have a MyGame.Person parent class and a MyGame.FireFighter class that gets loaded at runtime.
My problem is that when I use a Loader to load the external .swf and then try to do the cast to MyGame.Person, I get the following error:
TypeError: Error #1034: Type Coercion failed: cannot convert MyGame::FireFighter@2f05ebb1 to MyGame.Person
So it looks like the Loader's ApplicationDomain is different than the main .swf file's current ApplicationDomain, so FlashPlayer does not know that FireFighter is indeed a child of Person. What is the actual syntax for changing the Loader's ApplicationDomain to be the same as the main .swf's so that all the inheritance etc. works out.
Thanks!
Copy link to clipboard
Copied
That's great! Thanks for the response.

