xArray = [111,232,434];
buttonInstanceName.onPress = function(){
r = random(20);
for(i=0; i<r; i++){
xArray.push(xArray[0]);
xArray.shift();
}
person1._x = xArray[0];
person2._x = xArray[1];
person3._x = xArray[2];
}
- xArray = [111,232,434];
- buttonInstanceName.onPress = function(){
- r = random(20);
- for(i=0; i<r; i++){
- xArray.push(xArray[0]);
- xArray.shift();
- }
- person1._x = xArray[0];
- person2._x = xArray[1];
- person3._x = xArray[2];
- }
Now, for the line by line
xArray = [111,232,434];
^ This is an
array that holds the numbers we are going to use as _x positions, one for every movieclip we want to move.
buttonInstanceName.onPress = function(){
^This is the instanceName of the button that you want to trigger this function,
onPress is a dynamic event handeler,
=function(){ is standard for saying that the next few lines of code are going to be grouped together and run
onPress of
buttonInstanceName.
r = random(20);
^This is assigning a random number between 0 & 20 to a variable. Soon this number will be how many times we shuffle the array of numbers before using the numbers as _x positions.
for(i=0; i<r; i++){
^This is a
for loop, with how we are using it here it's basically saying, "
i equals zero to start with, as long as
i is less than the random number that was set for
r then do everything between
{ &
}, every time the things between
{ &
} have been done the add 1 to
i, check that
i is still less than
r, if it is then do everything between
{ &
} again."
xArray.push(xArray[0]);
^This tells our array to add whatever is at the beginning of the array to the end of the array.
xArray.shift();
^This removes the the item at the begining of the array. (see how the array elements are playing leapfrog for random turns ?)
}
^This ends the
for loop.
person1._x = xArray[0];
^This assigns the first number in the array as the _x position of the movieclip with the instanceName
person1
person2._x = xArray[1];
person3._x = xArray[2];
^Theese are the same as above just take note of how the number inside
[ ] changes.
}
^This ends out function.
Now what do you do with all of this you ask, you place it in the main timeline of your movie, place the movieclips on the stage, either change
buttonInstanceName to the instance name of your button or change the instance name of your button to
buttonInstanceName.
Change
person1(2,3) with the instance names of your person clips or vice versa.
Strong with this one, the sudo is.