 # [FMX] Random easing

I have a picture on the stage covered by 12 squares (sq1, sq2, sq3…sq12)
When the movie opens I want the squares to move down, but i want a random sequence ( 3, 9, 2, 12…8). I already made de function for the movement:

``````function moveClip(clip, ypos, snelheid) {
clip.onEnterFrame = function() {
var endY = ypos - this._y;
this._y += endY / snelheid;
if (Math.abs(endY)<2) {
this._y = ypos;
delete this.onEnterFrame;
}
};
}
``````

But I don’t now how to move the differens squares random with a interval from lets say .300.

Anybody?

[QUOTE=dboers]I have a picture on the stage covered by 12 squares (sq1, sq2, sq3…sq12)
When the movie opens I want the squares to move down, but i want a random sequence ( 3, 9, 2, 12…8). I already made de function for the movement:

``````function moveClip(clip, ypos, snelheid) {
clip.onEnterFrame = function() {
var endY = ypos - this._y;
this._y += endY / snelheid;
if (Math.abs(endY)<2) {
this._y = ypos;
delete this.onEnterFrame;
}
};
}
``````

something like this might work
myArray = [];
j = 0;
for (i=1; i<13; i++) {
this[“sq”+i].ypos = this[“sq”+i]._y+100;
myArray.push(this[“sq”+i]);
}
shuffle = function () {
return Math.round(Math.random());
};
// randomizes array
myArray.sort(shuffle);
function moveClip(clip, snelheid) {
clip._y += (clip.ypos-clip._y)/snelheid;
if (Math.abs(clip.ypos-clip._y)<2) {
clip._y = clip.ypos;
clearInterval(myInterval);
if (j<myArray.length-1) {
j += 1;
myinterval = setInterval(moveClip, 20, myArray[j], 20);
} else {
trace(“finished”);
}
}
}
myinterval = setInterval(moveClip, 20, myArray[j], 20);

This might give you a little more control

myArray = [];
j = 0;
for (i=1; i<13; i++) {
this[“sq”+i].ypos = this[“sq”+i]._y+100;
myArray.push(this[“sq”+i]);
}
shuffle = function () {
return Math.round(Math.random());
};
// randomizes jokes array
myArray.sort(shuffle);
function moveClip(clip, snelheid) {
clip.onEnterFrame = function() {
clip._y += (clip.ypos-clip._y)/snelheid;
if (Math.abs(clip.ypos-clip._y)<2) {
clip._y = clip.ypos;
delete clip.onEnterFrame;
}
};
}
function startoff() {
if (j<myArray.length) {
moveClip(myArray[j], 10);
j++;
} else {
clearInterval(myinterval);
trace(“finished”);
}
}
myinterval = setInterval(startOff, 300);

Thanks a lot stringy That works perfect. I only can’t figure out how to change the distance from the movements. The squares have an height of 360 pixels with the registration point top, so they have to move 360 pixels down

Thanks in advance you just need to change 100 in this line
this[“sq”+i].ypos = this[“sq”+i]._y+100;

Thanks a lot:thumb:

welcome