»Dotnet Ads
»Message Boards
Message Boards
Dotnet Books
»Member Details
Register
Login
LogOut
Submit Code
Submit Jobs
Submit Projects
»Competition
Community
Winners
Prizes
Write For Us
Members
»Other Resources
Links
Dotnet Resources
|
Moving a object to a specified pointLet's start.
1.Create a movieclip object of your choice. Here I created a amoeba object I gave it a instance name of "amoeba".
2.Create a mouse cursor . I created a movieclip with a red square , I gave it a instance name of "point".
3.Now comes the actionscript put the below code in the first frame.
//x,y are x and y axia position
//xl,yl are last position of movieclip
//xi,yi are x and y incremental values
x=amoeba._x;y=amoeba._y;
function pos()
{
xl = amoeba._x;
yl = amoeba._y;
xi = xl - x;
yi = yl - y;
xi = xi/150
yi = yi/150
if(yi < 0){yi = -yi;}
if(xi < 0){xi = -xi;}
}
function animate()
{
pos();
if(amoeba._x >= x){amoeba._x -= xi;}
if(amoeba._y >= y){ amoeba._y -= yi;}
if(amoeba._x <= x){amoeba._x = xi;}
if(amoeba._y <= y){ amoeba._y = yi;}
}
setInterval(animate,10);
point.onMouseDown=function()
{
x = this._x;
y = this._y;
}
point.onEnterFrame = function()
{
startDrag("point",true);
}
|
4.That's it test the movie. Click anywhere on the screen and you will see the amoeba object moves to that point.
|