Flash, ActionScript: loading assets from external SWF

We have a widget (SWF) that needs to be split into two SWFs. The main SWF will contain all the programming and business logic, and will also load the second SWF file, which will contain assets, fonts, etc.

I have limited experience with Flash, but I know it can be done in Flex. Anyway, we have to do it in Flash CS3. Can I do this in Flash? If so, what are the steps we need to follow?

Thanks Shri

+2


source to share


2 answers


Take a look at the Loader class . The code may be simpler than the example, but this is a start. There is a well explained tutorial on the flashandmath.com website.



In your main flush (with logic) create a loader, tell it to load assets, on Event.INIT, use assets.

+2


source


When loading assets from an external SWF, it is often useful to instantiate classes stored in the external SWF β€” for example, they are often referenced by fonts.

That being said, you have to make sure that your local SWF has a definition for these classes, and just compiling both SWF files together does not guarantee this. More specifically, if SWF depends on classes in another, then both SWF files end up carrying copies of the class definitions, and when you load the external SWF file at runtime, you get casting errors because the VM doesn't know the same named class in the external SWF is the same as the one you have.



To work around the issue you need to use ApplicationDomain.getDefinition()

in the loaded SWF - see here for a detailed example . In addition to a detailed use case, Loader

they also show how to get objects Class

from an external SWF.

+3


source







All Articles