tags:

views:

22

answers:

2

Is there a way to dispatch an event after Flex loads an mx:image? I'm loading image externally and don't know the width/height until it's loaded. I get an exception when I call width/height to the image before loading.

+1  A: 

you can attach listener for flash.events.Event.COMPLETE event. it is fired when image loading is complete.

sfaiz
+1  A: 

hi, you should use loader, in this case, like i have used in the below mentioned code

private var loader:loader = new Loader(); loader.load(new URLRequest(rp_product.dataProvider[i].@source)); loader.contentLoaderInfo.addEventListener(Event.COMPLETE,productLoadingComplete);
loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR,productLoadingError);

rp_product.dataProvider[i].@source, here rp_product is my repeater's id,

you simply give the image source here which u want to load, now you have productLoadingComplete() method, and productLoadingError() methods available, even if you want to something on image progess, so use this code :

loader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS,onImageLoadProgress);

in this way, you can load an external image, i hope this is wht u wre luking for

Ankur Sharma
How would I set the results from the loader to the image after it's complete? wouldn't setting the source property for mx:image triggers the image to automatically load the image?
Tam
private function productLoadingComplete(event:Event):void{ Image(Canvas(tile_product.getChildAt(i)).getChildAt(0)).source = event.target.content; Canvas(tile_product.getChildAt(i)).addEventListener(MouseEvent.CLICK,productSelected); removeSwfLoader();}
Ankur Sharma
ohhh, i m sorry, i'd have written this function on that day, see this is my productLoadingComplete() function, which is called, when the loader loads the image, just use the event.target.content(which is image)
Ankur Sharma
i m sorry dear, this is a bit complicated soln, to understand, but it's very easy when we do it, and one more thing, learn it very quickly, coz in future programming, atleast if i talk abt me, then i have to use this very much,
Ankur Sharma
in ur problem, when we r not sure , how much time the image or external data will take time to load, we use loader, on loader.contentloaderInfo, there r several event listners, like i have used, just i used the in built event listners, and called ma own functions, hope this helps, if this still a problem, i'll give u one demo application
Ankur Sharma
Thank you Ankur. well explained
Tam
your welcome buddy, hav a gr8 time
Ankur Sharma