Solved

can not dynamiacally load images in FLEX

Posted on 2008-10-20
5
1,453 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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

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…
Moving applications to the cloud or switching services to cloud-based ones, is a stressful job.  Here's how you can make it easier.
This video discusses moving either the default database or any database to a new volume.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

744 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

11 Experts available now in Live!

Get 1:1 Help Now