Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Loading an external SWF file and Instantiate Class From a swf in flex using as3

    • 0
    • 5
    • 2
    • 0
    • 1
    • 0
    • 0
    • 0
    • 1.24k
    Comment on it

    SWF files are loaded using the Loader class:
    1.Create a new URLRequest object with the url of the file.
    2.Create a new Loader object.
    3.Call the Loader object's load() method, passing the URLRequest instance as a parameter.
    4.Call the addChild() method on a display object container.

    Extract class reference by using:
    var C:Class= loader.contentLoaderInfo.applicationDomain.getDefinition("ClassName") as Class;

    package
     {
    import flash.display.Loader;
    import flash.display.MovieClip;
    import flash.events.Event;
    import flash.net.URLRequest;
    import flash.utils.getQualifiedClassName;
    
    import mx.core.UIComponent;
    
    public class SwfTest extends UIComponent
    {  private var loader:Loader;
    
        public function SwfTest()
        {
            super();
    
            var request:URLRequest = new URLRequest("swf file location");
             loader= new Loader()
            loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onLoaderReady);
            loader.load(request);
    
    
        }
        public function onLoaderReady(e:Event):void {     
    
        var C:Class= loader.contentLoaderInfo.applicationDomain.getDefinition("ClassName") as Class;
        var m:MovieClip = new C();
            //m.gotoAndStop(1);
         // m.gotoAndStop(1);
    
        this.addChild(m);
    
        }
    }
    }
    

 1 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: