HeadBanger606
06-27-2011, 12:58 PM
I have been trying for a week now to write a program that reads an external image file "png" and loads and displays it on screen. As far as I can tell this is how I should be doing it :
<?xml version="1.0" ?>
<mx:Application xmlns:mx="mxml" autoLayout="false">
<mx:Script>
<![CDATA[
import flash.display.*;
import flash.net.URLRequest;
import flash.events.Event;
public var container:Sprite = new Sprite();
public var imgLdr:Loader = new Loader();
public var imgURL:String = "img/enemy.png";
public var imgURLReq:URLRequest = new URLRequest(imgURL);
public function load_img():void {
imgLdr.load(imgURLReq);
imgLdr.contentLoaderInfo.addEventListener(Event.CO MPLETE,imgLoaded);
addChild(container);
}
public function imgLoaded(event:Event):void {
container.addChild(imgLdr);
}
]]>
</mx:Script>
<mx:Button id="test_btn" click="load_img()" label="Load Image" />
</mx:Application>
Nothing.. zilch. No errors, no image. Nothing. What am I doing wrong? I need to do it using action script, I'm working on a game engine and I need to dynamically add an image whenever I instantiate an enemy. But I can't even get this simple test to work?!? Thanks for any help.
<?xml version="1.0" ?>
<mx:Application xmlns:mx="mxml" autoLayout="false">
<mx:Script>
<![CDATA[
import flash.display.*;
import flash.net.URLRequest;
import flash.events.Event;
public var container:Sprite = new Sprite();
public var imgLdr:Loader = new Loader();
public var imgURL:String = "img/enemy.png";
public var imgURLReq:URLRequest = new URLRequest(imgURL);
public function load_img():void {
imgLdr.load(imgURLReq);
imgLdr.contentLoaderInfo.addEventListener(Event.CO MPLETE,imgLoaded);
addChild(container);
}
public function imgLoaded(event:Event):void {
container.addChild(imgLdr);
}
]]>
</mx:Script>
<mx:Button id="test_btn" click="load_img()" label="Load Image" />
</mx:Application>
Nothing.. zilch. No errors, no image. Nothing. What am I doing wrong? I need to do it using action script, I'm working on a game engine and I need to dynamically add an image whenever I instantiate an enemy. But I can't even get this simple test to work?!? Thanks for any help.