Hi all :)
I have a simple Image component, I change its source dynamically on creation.
myimg.source = "http://foo/bar.jpg"
How can i know when the image is loaded and received so that i can check its width ? Thanks
Hi all :)
I have a simple Image component, I change its source dynamically on creation.
myimg.source = "http://foo/bar.jpg"
How can i know when the image is loaded and received so that i can check its width ? Thanks
You should be able to add an event listener to the images event.creationComplete event to know when it's done being loaded. Or maybe it's event.progress. I'd take a look at the inherited events on the Image control and see which works.
in case you are working with flex: Set a render event on your image component:
<mx:Image id="theImage" render="yourFunction(event)"/>
In the script field:
private function yourFunction(evt:Event){
var theWidth= (evt.target as Image).width;
}
The render event is called when any displayobject is dispatched when the display list is about to be updated and rendered.
Flash (AS3.0):
//constructor function
public function CustomDisplayObject() {
theImage.addEventListener(Event.RENDER, renderHandler);
}
private function renderHandler(evt:Event):void {
var theWidth:int = evt.width;
}
(only tested in flex)