LibraryManager

Kind of class:public class
Package:org.casalib.util
Inherits from:none
Version:09/06/09
Author:Aaron Clinger
Classpath:org.casalib.util.LibraryManager
File last modified:Sunday, 06 September 2009, 09:07:10
Creates an easy way to store multiple libraries in groups and perform centralized retrieval of assets.
Example:
  • package {
        import flash.display.DisplayObject;
        import org.casalib.display.CasaMovieClip;
        import org.casalib.events.LoadEvent;
        import org.casalib.load.GroupLoad;
        import org.casalib.load.SwfLoad;
        import org.casalib.util.LibraryManager;
    
    
        public class MyExample extends CasaMovieClip {
            protected var _redLibLoad:SwfLoad;
            protected var _greenLibLoad:SwfLoad;
            protected var _groupLoad:GroupLoad;
    
    
            public function MyExample() {
                super();
    
                this._redLibLoad   = new SwfLoad("redExternalLib.swf");
                this._greenLibLoad = new SwfLoad("greenExternalLib.swf");
    
                LibraryManager.addSwfLoad(this._redLibLoad);
                LibraryManager.addSwfLoad(this._greenLibLoad);
    
                this._groupLoad = new GroupLoad();
                this._groupLoad.addLoad(this._redLibLoad);
                this._groupLoad.addLoad(this._greenLibLoad);
                this._groupLoad.addEventListener(LoadEvent.COMPLETE, this._onComplete);
                this._groupLoad.start();
            }
    
            protected function _onComplete(e:LoadEvent):void {
                var red:DisplayObject   = LibraryManager.createClassByName("RedBox");
                var green:DisplayObject = LibraryManager.createClassByName("GreenBox");
    
                green.x = 100;
    
                this.addChild(red);
                this.addChild(green);
            }
        }
    }

Summary


Constants
Class methods
  • addSwfLoad (swfLoad:SwfLoad, groupId:String = LibraryManager.GROUP_DEFAULT) : void
    • Adds a SwfLoad to LibraryManager.
  • removeSwfLoad (swfLoad:SwfLoad, groupId:String = LibraryManager.GROUP_DEFAULT) : void
    • Removes a SwfLoad from LibraryManager.
  • removeGroup (groupId:String) : void
    • Removes all SwfLoads from a group.
  • getGroupIdBySwfLoad (swfLoad:SwfLoad) : String
    • Determines which LibraryManager group contains a specific SwfLoad.
  • getGroupIdByDefinition (name:String) : String
    • Determines which LibraryManager group contains a specific definition.
  • getDefinition (name:String, groupId:String = LibraryManager.GROUP_DEFAULT) : Object
    • Gets a public definition from a library group.
  • hasDefinition (name:String, groupId:String = LibraryManager.GROUP_DEFAULT) : Boolean
    • Checks to see if a public definition exists within the library group.
  • getClassByName (className:String, groupId:String = LibraryManager.GROUP_DEFAULT) : Class
    • Retrieves a class from a library group.
  • createClassByName (className:String, arguments:Array = null, groupId:String = LibraryManager.GROUP_DEFAULT) : *
    • Instatiates a class from a library group.

Constants

GROUP_DEFAULT

public static const GROUP_DEFAULT:String = 'groupDefault'
(read)

Class methods

addSwfLoad

public static function addSwfLoad (
swfLoad:SwfLoad, groupId:String = LibraryManager.GROUP_DEFAULT) : void

Adds a SwfLoad to LibraryManager.
Parameters:
swfLoad:
The SwfLoad you wish to add.
groupId:
The identifier of the group you wish to add the SwfLoad to.

createClassByName

public static function createClassByName (
className:String, arguments:Array = null, groupId:String = LibraryManager.GROUP_DEFAULT) : *

Instatiates a class from a library group.
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.
groupId :
The identifier of the group you wish to instantiate the class from.
Returns:
  • A reference to the newly instantiated class or null if the className doesn't exist.

getClassByName

public static function getClassByName (
className:String, groupId:String = LibraryManager.GROUP_DEFAULT) : Class

Retrieves a class from a library group.
Parameters:
className:
The full name of the class you wish to receive from the loaded SWF.
groupId :
The identifier of the group you wish to retrieve the class from.
Returns:
  • A Class reference or null if the className doesn't exist.

getDefinition

public static function getDefinition (
name:String, groupId:String = LibraryManager.GROUP_DEFAULT) : Object

Gets a public definition from a library group.
Parameters:
name :
The name of the definition.
groupId:
The identifier of the group you wish to retrieve the definition from.
Returns:
  • The object associated with the definition or null if the name doesn't exist.

getGroupIdByDefinition

public static function getGroupIdByDefinition (
name:String) : String

Determines which LibraryManager group contains a specific definition.
Parameters:
name:
The name of the definition to determine which group it belongs to.
Returns:
  • The id for the containing group or null if the definition is not part of a group.
Usage note:
  • A definition could belong to more than one group.

getGroupIdBySwfLoad

public static function getGroupIdBySwfLoad (
swfLoad:SwfLoad) : String

Determines which LibraryManager group contains a specific SwfLoad.
Parameters:
swfLoad:
The SwfLoad to determine which group it belongs to.
Returns:
  • The id for the containing group or null if the SwfLoad is not part of a group.
Usage note:
  • A SwfLoad could belong to more than one group.

hasDefinition

public static function hasDefinition (
name:String, groupId:String = LibraryManager.GROUP_DEFAULT) : Boolean

Checks to see if a public definition exists within the library group.
Parameters:
name :
The name of the definition.
groupId:
The identifier of the group in which to search for the definition.
Returns:
  • Returns true if the specified definition exists; otherwise false.

removeGroup

public static function removeGroup (
groupId:String) : void

Removes all SwfLoads from a group.
Parameters:
groupId:
The identifier of the group you wish to empty.

removeSwfLoad

public static function removeSwfLoad (
swfLoad:SwfLoad, groupId:String = LibraryManager.GROUP_DEFAULT) : void

Removes a SwfLoad from LibraryManager.
Parameters:
swfLoad:
The SwfLoad you wish to remove.
groupId:
The identifier of the group you wish to remove the SwfLoad from.