Hello everyone.
I hope someone can help… I have a movieclip with a grid of 9 squares (3x3) what i would like to do is have each square move either on the x or y axis into a position of another square (like one of those puzzles where you move the tiles around to form a picture…) a random square in a random direction at random intervals…
I have tried editing the random movement tutorial on Kirupa, but i cannot get the effect i need…
http://www.kirupa.com/developer/mx/random_motionMX.htm
is this an easy task? - would someone care to point me in the right direction? - i would appreciate it if you could.
kind regards, and thanks in advance
Lee
I don’t think it should be too difficult. Randomize a variable between 0 and 3, each is a direction the box can move, and do it and random intervals. Something like [AS]
var totalSq = 9;
var squ = Math.round(Math.random()*(totalSq-1))+1;
var interval = Math.round(Math.random()*500); //which ever time you want
var direction = Math.round(Math.random()*3); //up,down,left,right - respectively
moveSq = function() {
direction==0 ? square[squ]._y -= square[sq]._height : null;
direction==1 ? square[squ]._y += square[sq]._height : null;
direction==2 ? square[squ]._x -= square[sq]._width : null;
direction==3 ? square[squ]._x += square[sq]._width : null;
clearInterval(intSq);
}
intSq = setInterval(movesq,interval);[/AS] and add upon that code
Thanks for the qiuck response, i am trying to get my head round that - sorry my AS is not that great -
so i have 9 squares on the stage named square1, square2 etc
and i have pasted this script into the first frame… and traced the variables to try and see whats going on, but i am a little confused.
can you elaborate a little further please…
thanks for your time
Lee