Flex Image Source Event, How do I know when a new source is received?

I have a simple image component, I am dynamically changing my source to create.

myimg.source = "http://foo/bar.jpg"

      

How do I know when an image has been loaded and received so that I can check its width?

+1


a source to share


2 answers


if you are working with flex: Set the render event to the 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 displayable is dispatched when the display list is refreshed 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)

+2


a source


You have to add event listener event event.creationComplete to know when it was loaded. Or maybe event.progress . I would look at the inherited events in the Image control and see what works.



+1


a source







All Articles