views:

30

answers:

1

Core of my code is following:

var img:Image = new Image;
img.source = 'http://..........';
img.autoLoad = true;
img.cachePolicy = 'on';

img.addEventListener(Event.COMPLETE, function(event:Event):void {
trace('Loaded!', img.source);
});
img.addEventListener(SecurityErrorEvent.SECURITY_ERROR, function(event:Event):void {
trace('Error!', img.source);
});
img.addEventListener(IOErrorEvent.IO_ERROR, function(event:Event):void {
trace('Error!', img.source);
});

I found that, the complete event does not occur for some images. How can I catch complete event without signal leaks?

+1  A: 

When you want to load an image (or even another swf) the class to use is Loader. A quick example:

var loader:Loader = new Loader();
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, handlerFunction);
loader.load(new URLRequest("http://somewhere/image.png"));

The only kind of tricky thing is that the events related to the loading are dispatched by the loader.contentLoaderInfo object, not the loader object.

And the always handy documentation: Loader Class

LopSae
Thank you for your help. I found that the problem is in another part of my code. I checked that all two styles work well - "img.src = ..." and "using Loader".
Jason