LibraryLoad

Kind of class:public class
Package:org.casalib.load
Inherits from:CasaLoader < LoadItem < BaseLoadItem < Process < RemovableEventDispatcher < EventDispatcher
Version:02/04/09
Author:Aaron Clinger, Mike Creighton
Classpath:org.casalib.load.LibraryLoad
File last modified:Tuesday, 10 February 2009, 17:24:35
Provides an easy and standardized way to load external SWF of class assets and instatiate them.
Example:
  • package {
        import flash.display.MovieClip;
        import flash.display.DisplayObject;
        import org.casalib.load.LibraryLoad;
        import org.casalib.events.LoadEvent;
    
    
        public class MyExample extends MovieClip {
            protected var _libraryLoad:LibraryLoad;
    
    
            public function MyExample() {
                super();
    
                this._libraryLoad = new LibraryLoad("myExternalLib.swf");
                this._libraryLoad.addEventListener(LoadEvent.COMPLETE, this._onComplete);
                this._libraryLoad.start();
            }
    
            protected function _onComplete(e:LoadEvent):void {
                var externalAsset:DisplayObject = this._libraryLoad.createClassByName("RedBox");
    
                this.addChild(externalAsset);
            }
        }
    }

    For embeded SWFs:
    package {
        import flash.display.MovieClip;
        import flash.display.DisplayObject;
        import org.casalib.load.LibraryLoad;
        import org.casalib.events.LoadEvent;
    
    
        public class MyExample extends MovieClip {
            protected var _libraryLoad:LibraryLoad;
    
            [Embed(source="myExternalLib.swf", mimeType="application/octet-stream")]
            protected const Boxes:Class;
    
    
            public function MyExample() {
                super();
    
                this._libraryLoad = new LibraryLoad(Boxes);
                this._libraryLoad.addEventListener(LoadEvent.COMPLETE, this._onComplete);
                this._libraryLoad.start();
            }
    
            protected function _onComplete(e:LoadEvent):void {
                var externalAsset:DisplayObject = this._libraryLoad.createClassByName("RedBox");
    
                this.addChild(externalAsset);
            }
        }
    }

Summary


Constructor
  • LibraryLoad (request:*, context:LoaderContext = null)
    • Creates and defines a LibraryLoad.
Class properties
Class properties inherited from Process
Instance methods
  • getDefinition (name:String) : Object
    • Gets a public definition from the loaded SWF.
  • hasDefinition (name:String) : Boolean
    • Checks to see if a public definition exists within the loaded SWF.
  • getClassByName (className:String) : Class
    • Retrieves an externally loaded class.
  • createClassByName (className:String, arguments:Array = null) : *
    • Instatiates an externally loaded class.

Constructor

LibraryLoad

public function LibraryLoad (
request:*, context:LoaderContext = null)

Creates and defines a LibraryLoad.
Parameters:
request:
A String or an URLRequest reference to the SWF you wish to load or the Class of the embeded SWF.
context:
An optional LoaderContext object.

Instance methods

createClassByName

public function createClassByName (
className:String, arguments:Array = null) : *

Instatiates an externally loaded class.
Parameters:
className:
The full name of the class you wish to instantiate from the loaded SWF.
arguments:
The optional parameters to be passed to the class constructor.
Returns:
  • A reference to the newly instantiated class.
Throws:
  • Error if method is called before SWF has loaded.

getClassByName

public function getClassByName (
className:String) : Class

Retrieves an externally loaded class.
Parameters:
className:
The full name of the class you wish to receive from the loaded SWF.
Returns:
  • A Class reference.
Throws:
  • Error if method is called before SWF has loaded.

getDefinition

public function getDefinition (
name:String) : Object

Gets a public definition from the loaded SWF.
Parameters:
name:
The name of the definition.
Returns:
  • The object associated with the definition.
Throws:
  • Error if method is called before SWF has loaded.

hasDefinition

public function hasDefinition (
name:String) : Boolean

Checks to see if a public definition exists within the loaded SWF.
Parameters:
name:
The name of the definition.
Returns:
  • Returns true if the specified definition exists; otherwise false.
Throws:
  • Error if method is called before SWF has loaded.