Groups | Blog | Home
all groups > flash actionscript > february 2005 >

flash actionscript : FLASH MASTERS NEEDED! - Loading images dynamically into Flash.


Byron Canfield
2/25/2005 11:32:23 AM
That requires a server-side soluton, such as a PHP program, to poll the
directory list for valid file types and create a data list, which your Flash
movie loads. There is no Flash-only solution; Flash cannot see the files in
the directory.

--
"There are 10 kinds of people in the world:
those who understand binary numbers and those who don't."
-----------------------------
Byron "Barn" Canfield
Flash example files: http://www.canfieldstudios.com

Byron Canfield
2/25/2005 5:37:33 PM
Sorry -- I'm PHP-ignorant; I just know Flash, alone, can't do it.

--
--------
Reality will not be altered to comply with preconceived notions.

Byron "Barn" Canfield
Flash example files: http://www.canfieldstudios.com

Quasimotolioli
2/25/2005 7:24:56 PM
THE PLAN: I am using Flash MX 2004 and I want to build something that loads a
series of .jpg images dynamically. I want the images to either load randomly
or sequentially, doesn't matter, from a images dir on my server. THE PROBLEM:
I have searched endlessly on the web in tutorials, forums, etc. for an answer
to this so there must a master out there somewhere to help me. I have made the
script in flash that can pull images into flash dynamically from a images
directory and rotate them in sequence just fine. HOWEVER, if I do not
predefine the image names (i.e. '1.jpg', '2.jpg, '3.jpg', etc.) then flash
doesnt know what the images are to load. ALSO, if I redefine a certain number
of images (i.e. 10) then if the image directory only contains 8 images , then
the animation rotates through the first 8, then two blank spaces, then
restarts. Its not smart enough to ignore the two blank images and just restart
the cycle without a gap in between. THE SOLUTION: So really I need something
that can rotate images dynamically that I dont have to define a specific number
of images or their specific file names before hand. That way I can just load
new images into that directory when I have them without ever having to update
that part of the flash file each time a want another image in the animation.
PLEASE help me or direct me to a URL that might have more info. Thanks
Quasimotolioli
2/25/2005 9:24:58 PM
Thanks Byron, So I have been looking at AMFPHP for my problem, but I still
wanted to use something that might be a bit simpler since that open source is
still very beta. Is there a simple way without something like AMFPHP to use a
modified combination of PHP and Flash to accomplish this?
van crouch
2/26/2005 2:52:21 AM
ok feller, here wew go.
keep in mind this all XML_

1).the script below will go in your first frame of your flash movie, O.k.
2). copy and past the XML script below, into an editor of your choice & save
as an XML.....
you can add as much pictures you want.

just rename the images to yours, and play with the delay rate.


delay = 11000;
//-----------------------
function loadXML(loaded) {
if (loaded) {
xmlNode = this.firstChild;
image = [];
description = [];
total = xmlNode.childNodes.length;
for (i=0; i<total; i++) {
image = xmlNode.childNodes.childNodes[0].firstChild.nodeValue;
description = xmlNode.childNodes.childNodes[1].firstChild.nodeValue;
}
firstImage();
} else {
content = "file not loaded!";
}
}
xmlData = new XML();
xmlData.ignoreWhite = true;
xmlData.onLoad = loadXML;
xmlData.load("images.xml");
/////////////////////////////////////
listen = new Object();
listen.onKeyDown = function() {
if (Key.getCode() == Key.LEFT) {
prevImage();
} else if (Key.getCode() == Key.RIGHT) {
nextImage();
}
};
p = 0;
this.onEnterFrame = function() {
filesize = picture.getBytesTotal();
loaded = picture.getBytesLoaded();
preloader._visible = true;
if (loaded != filesize) {
preloader.preload_bar._xscale = 100*loaded/filesize;
} else {
preloader._visible = false;
if (picture._alpha<100) {
picture._alpha += 5;
}
}
};
function nextImage() {
if (p<(total-1)) {
p++;
if (loaded == filesize) {
picture._alpha = 0;
picture.loadMovie(image[p], 1);
desc_txt.text = description[p];
picture_num();
slideshow();
}
}
}
function prevImage() {
if (p>0) {
p--;
picture._alpha = 0;
picture.loadMovie(image[p], 1);
desc_txt.text = description[p];
picture_num();
}
}
function firstImage() {
if (loaded == filesize) {
picture._alpha = 0;
picture.loadMovie(image[0], 1);
desc_txt.text = description[0];
picture_num();
slideshow();
}
}
function picture_num() {
current_pos = p+1;
pos_txt.text = current_pos+" / "+total;
}
function slideshow() {
myInterval = setInterval(pause_slideshow, delay);
function pause_slideshow() {
clearInterval(myInterval);
if (p == (total-1)) {
p = 0;
firstImage();
} else {
nextImage();
}
}
}

XML starts here..........

<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<images>
<pic>
<image>ImgHome1.jpg</image>
<caption>tax</caption>
</pic>
<pic>
<image>ImgHome2.jpg</image>
<caption>mortgage rates</caption>
</pic>
<pic>
<image>ImgHome3.jpg</image>
<caption>5 keys</caption>
</pic>
</images>
Quasimotolioli
3/1/2005 6:27:34 AM
awesome van crouch, this is exactly what i was looking for! Although since I'm
new to XML and Flash, what else do I need to do in flash to make sure that the
XML file and the SWF file are connected? I have made the flash file, and the
XML file, and the images. Should the image files be in the same dir as the
other files? Where do I define where the images will load into the Flash file?
I guess its really only this part that is confusing me b/c I'm not sure what
its loading here:
picture.loadMovie(image[p], 1); If the image path is 'image[p]' then is '1'
the name of the movie clip instance where it will load? Please advise, thank
you!
Quasimotolioli
3/3/2005 5:15:10 PM
Thanks for everyones help. But most importantly, thanks to Kirupa, who once
again has provided another great tutorial that is the solution to my problem.
Check it out: http://www.kirupa.com/developer/mx2004/xml_slideshow.htm Great
tutorial, easy to understand, and easy to modify.
AddThis Social Bookmark Button