PDA

View Full Version : simple dynamic pic loader


Spiff
04-07-2004, 07:56 AM
Hi,
One of the main features I'd like to have @ my site tnd2004.com (http://www.tnd2004.com) would be a "quick-portfolio". If u go there, you'll see a big 700x200 pic (it's the only one). Problem is it is static. I'd like it to be a *.swf file called "quick-portfolio", with two "fww" and "bck" arrows. That I can easily do - it's quite elementary.
The thing is I'd like to be always updating it, and the easiest way to do it would be just to upload the pics to a specific folder, and the *.swf file would auto get them :confused: ...
Ho, and I'd like that it would always load the pics randomly.
Think it's quite easy too, but I've never done it :o
Many thanks in advance :cool:

Ruben
04-07-2004, 09:50 AM
Hm, you might wanna have a look a the "loading Images via XML into Flash MX 2004" tutorial (http://www.actionscript.org/tutorials/intermediate/load_images_via_XML/index.shtml). That one teached me how to load external images into a dynamic textfield.

Next step is creating an array [click here for a tute on arrays (http://www.actionscript.org/tutorials/intermediate/Arrays/index.shtml)] with all the url's [relative or absolute, your choice] of the images you want the swf to load into itself...

Finally you'd just create the html for the textbox making it look something like this:

amountofimages = 4
imageVar = "<img src='img" + Math.round(Math.random()*amountofimages-1) + ".jpg'>"
// amountofimages is of course the amount of images stored in the array, in the second line it's decreased by 1 because arrays are zero-based, for more info on that check the arrays-tute ;)


I guess, that'd be it...Oh, allmost forgot: how about a search on the forum?

Good luck - Ruben

PS. When you use xml you can only load normal jpg's, progressive jpg's and gif's aren't allowed, or in other words: they simply won't load... ;)

xxlm
04-07-2004, 09:51 AM
look in the tuts section about dynamically loading backgrounds
you can use the php script for what you want, and send (a random name of a file contained in the folder) to flash which will load it.
Or you can send the entire "array" (in fact string and parsing to an array) and then selct a random index, displaying the picts.
Then next and previous will go to the next index or previous.
Hopes this helps... :)
C ya... and happy flashing

xxlm
04-07-2004, 09:56 AM
Oh I'm too slow...
But seeing your answer, would like to say that if you can use php, use my script. No need to edit the source (not the case for xml). Just upload your jpeg (or whatever, you can choose the extension) and it's making the rest... :):)
Advertising is always good... :) :) LOL

farafiro
04-07-2004, 10:27 AM
first you should save your pix names into a text file with the format ofmyPix=pic1,pic2,pic3
then u load this text file with all its info into your swf with the LoadVars() function, save them into an arrayvar thePix:Array = new Array();
var textVar:LoadVars = new LoadVars();
textVar.load("myPix.txt");
textVar.onLoad = function(okey) {
if (okey) {
_level0.thePix = this.myPix.split(",");
trace(_level0.thePix);
_level0.loadMovie(thePix[0]+".jpg");
}
};
then u can manage the pix flipping

farafiro
04-07-2004, 10:28 AM
oooops
me too is very late
but I'm outta say
mine is the best
:p

Spiff
04-07-2004, 12:15 PM
Tks ppl 4 the answers. Haven't tryed any yet, cause I'd like to ask u if any of your sugested methods avoid having to edit the *.swf or any other file everytime I upload new pics? That is:
I want to just upload the pics to a specific folder and let the *.swf file do the rest.
Again many tks in advance :cool:

Ruben
04-07-2004, 01:39 PM
The swf can't check [at least, not that I know of] what files there are in some folder or anything...

I suggest you use farafiro his method, then you only have to edit the txtfile in which all the filenames are placed...

Good luck - Ruben

xxlm
04-07-2004, 10:45 PM
Use my way mate...
As I told you. You just need to upload the file and php and flash will do the rest... :)
C ya...

Ruben
04-09-2004, 08:18 AM
Yeah, but does he know how to use PHP and how to combine it with Flash??

No offence or anything - Ruben

xxlm
04-09-2004, 09:49 AM
If he dunno, he just have to read the tuts mate... ;)
:p