Step 1 is to create an 'AS' file. Rename it as "MoveClass.as"
code for the class
class MoveClass{
private static var objToMove:String;
private var diffx:Number;
private var diffy:Number;
private var yPosNew1;
private var xPosNew1;
private var runClip:MovieClip;
public function MoveClass(target:MovieClip){
objToMove = target._name;
}
public var moveF:Function;
public function moveMe(xPosNew:Number,yPosNew:Number){
runClip = _root.createEmptyMovieClip("runclip",1);
runClip.onEnterFrame = function()
{
diffx = xPosNew-eval(MoveClass.objToMove)._x;
diffy = yPosNew-eval(MoveClass.objToMove)._y;
eval(MoveClass.objToMove)._x += diffx/4;
eval(MoveClass.objToMove)._y += diffy/4;
}
}
}
Step 2 - In the fla add following code for creating instance of the Class.
var mymv:MoveClass = new MoveClass(_root.mv1);
To call the method moveMe;
use below code.
mymv.moveMe(_root._xmouse,_root._ymouse);
Run the file and u r done.
Thanks
1 comment:
its very good nitin
Post a Comment