PDA

View Full Version : Random Images Or Shuffling With Flash?



understudy
April 21st, 2007, 08:23 PM
Hello,

Can Flash 'play' images in a different order—that is, shuffle the order?

For example, on http://www.texascapitolinvestors.com there is an image montage below the menu (it's 700K at present, but that will be fixed later). I'd like to use this same Flash movie on all the sub-pages, but I don't want them to see the same first image.

So, I'd either like to have Flash shuffle the images or start at a different point in the movie. How easy is that to do?

Thanks always.

My best,
David

//

kBisk
April 21st, 2007, 08:47 PM
var imageTotal:Number = 20; //set the number to choose from
var startImage:Number = random(imageTotal)+1; //selects 1-20 randomly

understudy
April 21st, 2007, 08:51 PM
Firstly, thank you.

Secondly, I've done a lot of presentations in Flash, but nothing requiring ActionScript.
Where do I place this in the .fla?

Thanks!

//


ActionScript Code:

var imageTotal:Number = 20; //set the number to choose from
var startImage:Number = random(imageTotal)+1; //selects 1-20 randomly

kBisk
April 22nd, 2007, 11:18 AM
Well depending on how the movie is setup... this would go in a frame on the timeline that uses the code (either the root timeline, or the movieclip).

understudy
April 22nd, 2007, 04:43 PM
Thanks again.

I'm not sure I set up the movie properly for this. I simply have two layers that are cross-fading. Here's the link to the fla file: http://www.texascapitolinvestors.com/main.fla

I would imagine that would be easier for someone looking at it than my trying to type the details.

My best,
David

//


Well depending on how the movie is setup... this would go in a frame on the timeline that uses the code (either the root timeline, or the movieclip).

stringy
April 22nd, 2007, 06:20 PM
maybe something like this on the first frame

keyframes = [1, 120, 240, 360];
if (myvar == undefined) {
f();
}
function f() {
onEnterFrame = function () {
if (this.getBytesLoaded()>=this.getBytesTotal()) {

myvar = keyframes[Math.floor(Math.random()*keyframes.length)];
this.gotoAndPlay(myvar);
delete this.onEnterFrame;
}
};
}

understudy
April 22nd, 2007, 08:34 PM
Stringy,

Awesome!

Seems to work perfectly.

Now, if I were wanting to understand ActionScript, are there any good online tutorials? the kind that at least take someone from novice to intermediate level?

Cheers,
David

//

PS: Many sincere thanks to kBisk also