开发者

FLEX - Load an image of type class instance

I have a barCode class that is used to generate an image of a barCode. I create an instance of this class and it works as expected for example:

var myBarCodeInstance:barCode = new barCode();

var myBarCodeImg:Image = new Image();
myBarCodeImg.source = myBarCodeInstance;

Using this code the image appears and works fine. However, my question is how do I implement a loader on this image that will fire an event when the image is fully loaded and ready for processing? (I am running into null problems with the image not being fully loaded b开发者_JS百科efore attempting to access its contents).

Something like the below:

var loader:Loader;

loader = new Loader();

loader.contentLoaderInfo.addEventListener(Event.COMPLETE,function(e:Ev ent):void{
myBarCodeImg.source = e.currentTarget.content;
// further processing here
});

loader.load(new URLRequest(encodeURI(“image.jpg“)));

but i dont know what to insert in place of the "image.jpg" part due to my image being an instance of a class and not an actual jpg file.


Image dispatches a complete event - try listening for that event:

var myBarCodeInstance:BarCode = new BarCode();
var myBarCodeImg:Image = new Image(); 
myBarCodeImg.addEventListener(Event.COMPLETE, completeHandler);
myBarCodeImg.source = myBarCodeInstance;

function completeHandler(e:Event):void
{
    var img:Image = e.currentTarget as Image;
    var barcode:BarCode = img.content as BarCode;
    /* process it */
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜