1

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;
}

3 Answers3

1
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;
gMirian
  • 651
  • 7
  • 13
  • the thing is, I have 10 MCs on my stage and I need to set 10 positions, or Points. –  Nov 16 '13 at 18:07
  • To set position you need to set x and y coordinates, so in any case ex: myObject.x=someValue; need to be used, so in your case it would look like: myObject.x = positionsp[0].x; myObject.y = positionsp[0].y; and so on. – gMirian Nov 16 '13 at 19:10
0

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).

Szczups
  • 131
  • 4
0

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);
Wilson Silva
  • 10,046
  • 6
  • 26
  • 31