user1832012
user1832012

Reputation:

Actionscript 3 move object to Point

ok guys, I decided to rework my question quite a bit:

there are 10 various points on the stage I would like to work with (I would like to dynamically place my object there)

var myPoint_1 should have x = 100 and y = 100 var myPoint_2 should have x = 50 and y = 80 and so on...

function moveObject(posX,posY):void
{
    myObject.x = posX;
    myObject.y = posY;
}

IS THERE A WAY TO REPLACE posX AND posY with ONE VARIABLE? I have something like this in mind:

-move object to myPoint_1:

function moveObject(myPoint_1):void
{
    myObject.x = posX;
    myObject.y = posY;
}

or -move object to myPoint_2:

function moveObject(myPoint_2):void
{
    myObject.x = posX;
    myObject.y = posY;
}

Upvotes: 1

Views: 2235

Answers (3)

Wilson Silva
Wilson Silva

Reputation: 11385

Your function should look like this:

function moveObject(destination:Point):void
{
    myObject.x = destination.x;
    myObject.y = destination.y;
}

Then all you have to do is declare the points and call it using each point as parameter:

var myPoint_1 = new Point(100, 100);
var myPoint_2 = new Point(50, 80);

moveObject(myPoint_1);
moveObject(myPoint_2);

Upvotes: 0

Szczups
Szczups

Reputation: 121

If you want to avutally see object moving from point A to B - and not only set its position, I highly recomment various transition libraries - especially Greensock's TweenLite - http://www.greensock.com/v12/ (for ActionScript and js).

Upvotes: 0

gMirian
gMirian

Reputation: 651

myObject.x=200;
myObject.y=200;

You don't need Point there, it's not ncessary, but anyway if you want to use after settings values here it is:

myObject.x=myPoint.x;
myObject.y=myPoint.y;

Upvotes: 1

Related Questions