Search code examples
flashactionscript-3programming-languages

Error with external file loading


I tried to load an image in the same folder of the flash but it didn't work.

package  {

import flash.display.MovieClip;
import flash.net.URLLoader;
import flash.net.URLRequest;
import flash.display.Stage;


public class engine extends MovieClip {
    var imgRequest:URLRequest = new URLRequest("cloud.jpg");
    var imgLoader:URLLoader = new URLLoader();
    var sym:Symbol2= new Symbol2;

    public function engine() {
        imgLoader.load(imgRequest);
        addChild(imgLoader);
        trace(imgLoader);


    }
}

}

F:\test\engine.as, Line 16  1067: Implicit coercion of a value of type flash.net:URLLoader to an unrelated type flash.display:DisplayObject.

Could you teach me how to solve this problem? I tried many ways but still didn't get it right T_T


Solution

  •     import flash.display.Loader;
        import flash.events.Event;
        import flash.net.URLRequest;
    
        var loader : Loader = new Loader( );
            loader.contentLoaderInfo.addEventListener(Event.COMPLETE, completeHandler );
            loader.load( new URLRequest( "cloud.jpg" ) );
    
    
    
        function completeHandler ( eventOBJ : Event ) : void
        {
            addChild( loader.content );
        };