Friday, December 5, 2008

panning using Flash AS 2.0 code

Hi
I like to put a small game code for moving a object with ease

create a movie clip with some thing like face or ball or what ever inside it.
place the movie clip inside the work Area name it as obj. copy and paste the code below in the first frame and execute now where ever you click the mouse your object follow it....
Done...

//your code hear
var mouseListener:Object = new Object();
mouseListener.onMouseDown = function() {
_global.xpoint = _xmouse;
_global.ypoint = _ymouse;
};
Mouse.addListener(mouseListener);

obj.onEnterFrame = function() {

var dy:Number;
var dx:Number;
dx = 0;
dy = 0;
dx = ((_global.xpoint)-this._x)/5;
dy = ((_global.ypoint)-this._y)/5;
if (Math.abs(dx)<0.4) {
dx = 0;
} else {
this._x += dx;
}
if (Math.abs(dy)<0.4) {
dy = 0;
} else {
this._y += dy;
}
};
//End of your code

cool fine

No comments: