Solved

can not dynamiacally load images in FLEX

Posted on 2008-10-20
5
1,457 Views
Last Modified: 2012-05-05
Hello there,

I am trying to load images in flex 3 dynamically. I have the image file name start with same number and with a trailer like 15652_1.jpg, 15652_2.jpg,15652_3.jpg...but I did not know how many of them.
If I use a small loop like

for (var i:int=1; i<20; i++){ var img:Image=new Image();
img.source="../Photos/"+"15652"+"_.jpg";
holder.addChild(img);
}
I will have images add into the holder but with broken image from 13 to 20 because it's not there.

I was trying with
private function getphoto():void{
for (var i:int=1; i<20; i++){
var loaderi:Loader=new Loader();
var ui:UIComponent=new UIComponent();
var requesti=new URLReruest=("../Photos/"+"15652"+"_.jpg");
loaderi.load(requesti);
ui.addChild(loaderi)
hoder.addChild(ui)
} }
I will got
Error #2044: Unhandled IOErrorEvent:. text=Error #2036: Load Never Completed. for the first 11 images
only the last one loaded.
My question is is there a way I can loop through image and detect what file was not in the folder and not adding them to the folder?
Or if I have to use loader then why only the last one was shown?
Thanks for your answer.
0
Comment
Question by:tomcattyy
  • 3
  • 2
5 Comments
 
LVL 19

Expert Comment

by:Gary Benade
ID: 22766445
Is the code you posted correct? You are not using the variable i in the filename?

var requesti=new URLReruest=("../Photos/"+"15652"+"_" + i + ".jpg");
0
 
LVL 1

Author Comment

by:tomcattyy
ID: 22767976
Sorry for the typo, I do have the i in file name for both image, and loader
0
 
LVL 19

Accepted Solution

by:
Gary Benade earned 500 total points
ID: 22768832
OK. An IOError means the file could not be found, as a starting point you could try changing your url's to absolute:

var requesti=new URLReruest=("http://yourserver/Photos/"+"15652_" + i + ".jpg");

As a test, if you can open the path http://yourserver/Photos/15652_5.jpg in a browser then it's OK and the loader should load it.
0
 
LVL 1

Author Comment

by:tomcattyy
ID: 22769499
I am transfering it to the web server, so far I am testing from the local machine. Will advice results shortly. thanks
0
 
LVL 1

Author Comment

by:tomcattyy
ID: 22769729
Hello hobbit72,

That's super, I got it to run after the absolute path and with try catch steps like
try {    loaderi.load(requesti);}
      catch (error:SecurityError) {
    trace(error);}
ui.addChild(loaderi);ui.y=260*(i-1); ui.x=50;
holder.addChild(ui)

and It sowed up. Thanks
0

Featured Post

Do email signature updates give you a headache?

Are you constantly making changes to email signatures? Are the images not formatting how you want them to? Want high-quality HTML signatures on all devices, including on mobiles and Macs? Then, let Exclaimer solve all your email signature problems today.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

First things first - Preparation We need all the part for this install and it's much nicer to have them all on hand when you need them so here's what's required. Download Eclipse 3.5 32 bit (I like the Classic flavour) from here. (http://www.e…
There are many Password Managers (PM) out there to choose from. PM's can help with your password habits and routines, but they should not be a crutch you rely on too heavily. I also have an article for company/enterprise PM's.
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now