Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Random image help

Status
Not open for further replies.

technoknow

Technical User
Apr 19, 2002
121
US
Here is my script:
index = random()*(5-1)+1;
imageToDisplay = _root["image" + index];
this.attachMovie(imageToDisplay, "randomImage", 0);

I get the error message:
"Wrong number of parameters; random requires exactly 1.
index = random()*(5-1)+1;"

So I tried:
random(5);

Which doesn't generate an error message but puts code onto the page.

I have 6 mc's in the library named image1, image2, etc.
and in linkage "export for actionscript" is checked for each.
I have a mc named "randomImage" on the stage in frame 1
The script is on frame1
Any ideas?
Thanks,
TechNoKnow
 
index = random(6)+1;
//Or the new Math.random...
//index = Math.round(Math.random()*5+1);
imageToDisplay = "image" + index;
trace(imageToDisplay);
//
this.attachMovie(imageToDisplay, "randomImage", 10);

As for "randomImage", it's not a movie clip on stage, it's the new name of the random attached movie clip from the Library, that will be given to the clip that will be created (attached) on stage. Delete your "randomImage" clip.

Thus after the imageToDisplay is created on stage, you would refer to it with "randomImage", to set it's alpha for example...

_root.randomImage._alpha = 50;
 
Thanks, that works great!
Here is my code:
index = Math.round(Math.random()*5+1);
imageToDisplay = "image" + index;
this.attachMovie(imageToDisplay, "randomImage", 1);
_root.randomImage._x = 350;
_root.randomImage._y = 250;

Now I'm trying to have multiple instances of this randomImage on the same page. I've tried just renaming the vars:
index1 = Math.round(Math.random()*5+1);
imageToDisplay1 = "image" + index1;
this.attachMovie(imageToDisplay1, "randomImage1", 2);
_root.randomImage1._x = 350;
_root.randomImage1._y = 250;

But this just creates the imageToDisplay1 and skips the original imageToDisplay.
More help oldnewbie?
Thanks,
TechNoKnow
 
oops I meant to post that I changed the
_root.randomImage1._X = 550;
_root.randomImage1._Y = 250;
 
I've been reading about duplicateMovieClip, would that be the way to go about it?
TechNoKnow
 
So you want to end up with the 6 different pictures on stage but in random positions, is that it? And if so, I guess you don't want the same picture to be repeated, right?
 
What I'd like to end up with is 6 different windows in predetermined positions that are each showing a random picture.
It doesn't matter that they will show the same picture.
I've been messing with it more and have figured out that the code you gave me will work fine if I just change the variable names and change the depth, so I think I have it working now.
So thanks, now I'm working on a timer so they will change every few seconds, in random order.
I'll problably need your help with that but I'll spend some time on it first.
Thanks,
TechNoKnow
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top