PDA

View Full Version : Trying to use random() in function


skalie
05-22-2005, 03:07 PM
// Edit found it, see second post

Howdy, this is probably something basic logistically that is passing above my head at the moment..... (actionscript 2)

I have two movies, I want them to change colour at random, so I exported them for actionscript using the names "p" and "o".

I made a function then call it, twice. My script...


function tester(sLink:String){
var mcTester:MovieClip = this.attachMovie(sLink,sLink,getNextHighestDepth() );
var colour:Color = new Color(this);
mcTester.onEnterFrame = function(){
colour.setRGB(Math.random()*0xFFFFFF);
}
}
tester("p");
tester("o");


Problem is, both movies change to the same colour at the same time.

Any of you guru's see what I'm doing wrong? I would have thought that I would have two functions running, therefore two random colours.

TIA

skalie
05-22-2005, 03:50 PM
Here was the culprit...


var colour:Color = new Color(this);


It was changing the colour of the whole movie, doh!

The fix...


var colour:Color = new Color(mcTester);