We are building a bookstore and have one bug we can't figure out. Some of the items' thumbnail images are missing. We wrote some code that tries to load the image, and if it doesn't load correctly it replaces it with a default image. The problem is, the function is returning the string before the image loads or fails and therefore isn't returning the right data.

Any suggestions?

I'll paste our current code below:

The image tag:

<mx:Image id="img" height="160" source="{sendImage(of.currentItem.prod.getItemAt(O).image)}" ioError="strUse='assets/pic/defaultITM.jpg'"/>

The function:

private function sendImage(str:String):String

{                                              

                                    var path:String = "assets/pic/";               

                                    var strUse:String = str;

                                    // Looks to see if the image exists

                                    var ldr:URLLoader = new URLLoader();

                                    ldr.addEventListener(IOErrorEvent.IO_ERROR, imgFailed);

                                    ldr.addEventListener(Event.COMPLETE, imgCompleted)

 

                                    function imgFailed (e:IOErrorEvent):void {

                         strUse = "defaultITM.jpg";

            }

            function imgCompleted (e:Event):void{

                        strUse = str;

            }

                                    var url:String = "http://dev.ourserver.org/assets/pic/" + str;

                                    var urlReq:URLRequest = new URLRequest(url);

                                    ldr.load(urlReq);                        

                                     

                                    return path + strUse;                 

}

 

__._,_.___

--
Flexcoders Mailing List
FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.com





SPONSORED LINKS
Software development tool Software development Software development services
Home design software Software development company

Your email settings: Individual Email|Traditional
Change settings via the Web (Yahoo! ID required)
Change settings via email: Switch delivery to Daily Digest | Switch to Fully Featured
Visit Your Group | Yahoo! Groups Terms of Use | Unsubscribe

__,_._,___

Reply via email to