Version – 0.91, updated 2010/11/20
Compatibility - AS3 (Flash Player 9 and later)
You can load fonts and movieclips from a swf at runtime using applicationDomain. It works and does the job pretty good if you just want to load a few object. You can do it like the code below, but I suggest you give this little lib a try.
var l:LoaderInfo = loader.content.loaderInfo;
var cls:Class=l.applicationDomain.getDefinition("fontClassNameHere") as Class
Font.registerFont(cls);
var l:LoaderInfo = loader.content.loaderInfo;
var cls:Class=l.applicationDomain.getDefinition("movieClipClassName") as Class
var clsObj:Object = new cls();
addChild(DisplayObject(clsObj));
Features
Fonts - Load and register fonts at runtime.
MovieClips ans sprites - Load graphics from a swf-file at runtime.
Sound - Load sound from a swf-file at runtime.
Video - Coming in the next version.
Preloader - Let the library send you updates on how many bytes have loaded.
Safemode - The loader will alert you if you name two librarys the same. Defaults to false.
Usage
- In the Flash IDE, select “Export for ActionScript” in the Linkage settings of the symbol you want to use.
- Publish the file to a SWF.
- Import it into your project with SwfLibrary.
- Access the asset like in the sample code below.
Demo
Source code
I know, I should put this stuff on Git. But until then here is a zip-file with the source code.
Download SwfLibrary source – Download demo fla´s (Source needed)
Documentation
Public methods
- add(val:Object,safemode:Boolean) – Add swf-files to the queue.
- append(val:Object,safemode:Boolean) – Add a file after the queue as loaded.
- progress() – Set to false if no progress events should be fired.
- load() – Start to load the queue.
- debug() – Set to true if you want to trace stuff. Defaults to false.
- font(library:String,assetClass:String) – Get a fontfile from the library.
- item(library:String,assetClass:String) – Get a movieclip from the library.
- sound(library:String,assetClass:String) – Get a soundclip from the library
Events
- Event.COMPLETE – Fired when all loaders have loaded.
- Event.CHANGE – Get how many percent are loaded. Ex: ”e.currentTarget.percentLoaded”.
