Thursday, January 1, 2009

Create a simple class AS2.0 - MoveClass

Requirement is to make a simple class which has a method move to allow moving of MovieClips on stage with its moveMe method.

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:

Unknown said...

its very good nitin

Using FormBuilder, Validators & FormGroup in Angular 2 to post data to Node server (node.js)

This blog explains usage of  FormBuilder , Validators , FormGroup classes in Angular 2 projects. In this post we will create HTML form a...