PDA

View Full Version : Random image loading from txt file



Cello
September 30th, 2003, 03:37 AM
Hi all - need your help; am having major brain burp...

I want to have a background image that randomly loads from a list of *.jpg files in a txt file. The txt file is to be edited by user (to add a new image) without accessing the code contained in the .fla, and the txt file gives the location of the images.

It is possible I know - but my old head isn't working. :h:

I need this for a charity that I do free work for; any pointers would be a huge help.

(Have searched forums, BTW, but nothing exactly matches - honest :beam: )

Thx all.

claudio
September 30th, 2003, 09:25 AM
You can use something like this:loadText = new LoadVars();
loadText.onLoad = function(success) {
if (success) {
var pictures_array = this.pictures.split('|');//split the content of txt file into an array
container_mc.loadMovie(pictures_array[random(pictures_array.length)] )
}
};
loadText.load("textfile.txt");
//your textfile should look like this:
//pictures=home.jpg|cat.jpg|car.jpg&
//if the person wants to update the txt file, just separate the file names with a |

Cello
September 30th, 2003, 10:58 AM
edited to say sorted an initial problem (coding - me being stupid :) )

However, now that MX is accepting the code, it is stubbornly refusing to display the .jpg (I've checked that the jpg are all RGB, the right size, etc)

(I assume that the code goes into an empty MC called container_mc)

Many thx claudio - look forward to getting this to work - the code is excellently straightforward - it's me that doesn't work quite as well :sigh:

claudio
September 30th, 2003, 12:00 PM
Here is one example

Cello
October 1st, 2003, 10:57 AM
Ha :) - that did the trick.

As ever, thx for your help claudio :beam:

claudio
October 1st, 2003, 11:31 AM
Anytime Cello ;)