Shuffling movie clips

I got this script where if you have

1 2 3 4 5

and i click on the 5 it will arrange the movie clips so they will be

5 1 2 3 4

That works correctly

However what i’m trying to do now is that if you have

1 2 3 4 5

and i click on the 1 it will be

2 3 4 5 1

This has been a pain :frowning:

i need some help :frowning:

I don’t know how to change my moveme function
so it will work this way


var acceleration = 12;
var friction = 0.7;

var clipArray = new Array();
var posArray = new Array();

var currentArray = new Array();
var xspeed:Number;

for (var d = 0; d<5; d++) 
{
	myclip = attachMovie("mc", "mc"+d, d);
	myclip._y = 100;
	myclip._x = 170+myclip._width*d;

	clipArray.push(myclip);

	posArray.push(myclip._x);
	myclip.onPress = dostuff;
}

function moveme() 
{
	var xdif = Number(posArray[this.jvar]-this._x);
	this.xspeed += xdif/this._parent.acceleration;
	this.xspeed *= this._parent.friction;
	this._x += this.xspeed;
	checkDistance();
}

checkDistance = function () {
	if (Math.abs(posArray[this.jvar]-this._x)<1) 
	{
		this._x = posArray[this.jvar];
		delete this.onEnterFrame;
	}
};

function dostuff() 
{
	var flag:Boolean;
	InitializeArray();

	for (var i = 0; i<clipArray.length; i++) {
		// setting indexes 
		clipArray*.ivar = i;
	}
	
	// deleting the mc the user clicked
	k = clipArray.splice(this.ivar, 1);

	// the mc you click is on the front
	clipArray = k.concat(clipArray);
	
	for (var j = 0; j<posArray.length; j++) 
	{
		// re setting the indexes
		clipArray[j].jvar = j;
		//trace(clipArray[j]+" "+clipArray[j].jvar);
		// calls move
		clipArray[j].xspeed = 0;
		flag = ClickedCorner();
		//trace(flag);
		if(flag)
		{
			clipArray[j].onEnterFrame = moveme;
		}
		else
		{
			//ShuffleAgain();
		}
	}
	
	//ActualArray();
}

function ClickedCorner() : Boolean {

	if(currentArray[4] == clipArray[0])
	{
		return true;
	}
	else
	{
		return false;
	}
}

function ShuffleAgain()
{
	for(var t = 0; t < 5; t++)
	{
		 clipArray[t] = currentArray[t];										 
	}
	
	/*for( t = 0; t < 5; t++)
	{
		 trace("Shuffle Again " + clipArray[t]);										 
	}*/
}

function InitializeArray()
{
	for(var row = 0; row < 5; row++)
	{
		 currentArray[row] = clipArray[row];										 
	}
	
	/*for( row = 0; row < 5; row++)
	{
		 trace("Initial Array " + currentArray[row]);									 
	}*/
}

function ActualArray()
{
	for( var r = 0; r < 5; r++)
	{
		 trace("Actual Array " + clipArray[r]);										 
	}
}