Actionscript: How Can I Know When The Source Property Of An Image Is Completely Updated

Posted by Joshua on Stack Overflow See other posts from Stack Overflow or by Joshua
Published on 2010-05-31T21:05:49Z Indexed on 2010/05/31 21:13 UTC
Read the original article Hit count: 222

var I:Image=new Image();
I.source='C:\\Abc.png';
var H:int=I.height;

H is always Zero!

I am presuming this is because the image hasn't finished reading the png file off the disk yet.

What event can I monitor to know when it's width and height will have the right values?

The 'Complete' event only seems to work for DOWNLOADED images. The 'Render' event happens EVERY FRAME. The (undocumented?) 'sourceChanged', happens as soon as source changes, and has the same problem!

What event do I watch that will let me know when the image's width and height properties will have valid values? Or is there some Synchronous version of I.source='xxx.png', that I don't know about?

P.S. Yes, I know I shouldn't use "C:\" in an Air Program. This was just for illustrative purposes, so that you won't suggest I use "Complete", which never even seems to fire when the file indicated by source is local.

© Stack Overflow or respective owner

Related posts about flex

Related posts about flash