SwfLoad

Kind of class:public class
Package:org.casalib.load
Inherits from:CasaLoader < LoadItem < Process < RemovableEventDispatcher < EventDispatcher
Version:09/06/09
Author:Aaron Clinger, Mike Creighton
Classpath:org.casalib.load.SwfLoad
File last modified:Sunday, 06 September 2009, 09:35:30
Provides an easy and standardized way to load SWF files and external class assets.
Example:
  • package {
        import org.casalib.display.CasaMovieClip;
        import org.casalib.events.LoadEvent;
        import org.casalib.load.SwfLoad;
    
    
        public class MyExample extends CasaMovieClip {
            protected var _swfLoad:SwfLoad;
    
    
            public function MyExample() {
                super();
    
                this._swfLoad = new SwfLoad("external.swf");
                this._swfLoad.addEventListener(LoadEvent.COMPLETE, this._onComplete);
                this._swfLoad.start();
            }
    
            protected function _onComplete(e:LoadEvent):void {
                this.addChild(this._swfLoad.contentAsMovieClip);
            }
        }
    }

    For external classes:
    package {
        import flash.display.DisplayObject;
        import org.casalib.display.CasaMovieClip;
        import org.casalib.events.LoadEvent;
        import org.casalib.load.SwfLoad;
    
    
        public class MyExample extends CasaMovieClip {
            protected var _swfLoad:SwfLoad;
    
    
            public function MyExample() {
                super();
    
                this._swfLoad = new SwfLoad("myExternalLib.swf");
                this._swfLoad.addEventListener(LoadEvent.COMPLETE, this._onComplete);
                this._swfLoad.start();
            }
    
            protected function _onComplete(e:LoadEvent):void {
                var externalAsset:DisplayObject = this._swfLoad.createClassByName("RedBox");
    
                this.addChild(externalAsset);
            }
        }
    }

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

Summary


Constructor
  • SwfLoad (request:*, context:LoaderContext = null)
    • Creates and defines a SwfLoad.
Class properties
Class properties inherited from Process
Instance properties
  • contentAsMovieClip : MovieClip
    • The data received from the DataLoad data typed as MovieClip.
  • contentAsAvm1Movie : AVM1Movie
    • The data received from the DataLoad data typed as AVM1Movie.
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

SwfLoad

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

Creates and defines a SwfLoad.
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 properties

contentAsAvm1Movie

public contentAsAvm1Movie:AVM1Movie
(read)

The data received from the DataLoad data typed as AVM1Movie. Available after load is complete.
Throws:
  • Error if method is called before the SWF has loaded.
  • Error if method cannot convert content to an AVM1Movie.

contentAsMovieClip

public contentAsMovieClip:MovieClip
(read)

The data received from the DataLoad data typed as MovieClip. Available after load is complete.
Throws:
  • Error if method is called before the SWF has loaded.
  • Error if method cannot convert content to a MovieClip.

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 the 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 the 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 the 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 the SWF has loaded.