Hellow i doo this plz check and advice

hi i am new be in flash, i am trying to like this and i Done!

http://myrozgar.noads.biz/flash/

check this but you are laughing to see my code how i done this. i have 4 Mc and all have separate function but its is stupid thing. Any expert can combine to one function.

thanks in advance

Here is Code

onMouseMove = function(){
total.onEnterFrame = function(){
diffx = _root._xmouse - this._x ;
diffy = _root._ymouse - this._y ;

/// 5 is distance between the mouse and the movie clip

total._x += diffx/5 ;
total._y += diffy/5 ;
total._alpha = 50;
//root.line_mc.lineTo(this._x , this._y) ;
}

total1.onEnterFrame = function(){
diffx = _root._xmouse - this._x ;
diffy = _root._ymouse - this._y ;

/// 5 is distance between the mouse and the movie clip

total1._x += diffx/3 ;
total1._y += diffy/3 ;
total1._alpha = 100;

//root.line_mc.lineTo(this._x , this._y) ;
}

total2.onEnterFrame = function(){
diffx = _root._xmouse - this._x ;
diffy = _root._ymouse - this._y ;

/// 5 is distance between the mouse and the movie clip

total2._x += diffx/7 ;
total2._y += diffy/7 ;
total2._alpha = 40;

//root.line_mc.lineTo(this._x , this._y) ;
}

total3.onEnterFrame = function(){
diffx = _root._xmouse - this._x ;
diffy = _root._ymouse - this._y ;

/// 5 is distance between the mouse and the movie clip

total3._x += diffx/9 ;
total3._y += diffy/9 ;
total3._alpha = 30;

//root.line_mc.lineTo(this._x , this._y) ;
}}

Try this…


function commonEnterFrame(){
	diffx = _root._xmouse - this._x ;
	diffy = _root._ymouse - this._y ;
	this._x += diffx/this.speed;
	this._y += diffy/this.speed;
	this._alpha = this.alphaTo;
}

total.onEnterFrame  = commonEnterFrame;
total1.onEnterFrame = commonEnterFrame;
total2.onEnterFrame = commonEnterFrame;
total3.onEnterFrame = commonEnterFrame;

total.alphaTo  = 50;
total1.alphaTo = 100;
total2.alphaTo = 40;
total3.alphaTo = 30;

total.speed  = 5;
total1.speed = 3;
total2.speed = 7;
total3.speed = 9;

You could simplify the code even more using arrays and for loops.

how can with loops and arrays???

thanks

You’ll need to name your movieclips sequentially e.g total1, total2, …


for(i=1;i<5;i++)
{
	this["total"+i]._alpha = 100-i*20;
	this["total"+i].speed  = i*3;
	this["total"+i].diffx = this["total"+i].diffy = 0;
}

this.onEnterFrame=function()
{
	for(i=1;i<5;i++)
	{
		mc = this["total"+i];
		mc.diffx = _root._xmouse - mc._x ;
		mc.diffy = _root._ymouse - mc._y ;
		mc._x += mc.diffx/mc.speed;
		mc._y += mc.diffy/mc.speed;
	}
}