PDA

View Full Version : move object to x, y position when clicked


m282
02-15-2011, 11:23 PM
Hi.

How to move a object to x, y position when I click the object?

Example:

I have 10 to 20 images on the form and both them are image, If I select one of them I wanted to move it to the right x, y position and stretch as well.

Thanks!

Regards

anndorian
02-16-2011, 09:52 AM
object1.addEventListener(MouseEvent.CLICK, Move);
object2.addEventListener(MouseEvent.CLICK, Move);
object3.addEventListener(MouseEvent.CLICK, Move);

function Move($e:MouseEvent):void
{
$e.target.x = 200;
$e.target.y = 150;
}

This is just to put you on the right track.

thomas199922
02-16-2011, 10:48 AM
I think you should use an eventListener which listens for when the picture is clicked and then change the x and y positions... for example:


your_button_name.addEventListener(MouseEvent.CLICK , change_positions);
function change_positions(e:MouseEvent){
your_button_name.x = whatever position along the x axis you want the picture to be on
your_button_name.y = same thing along the y axis
your_button_name.width = how wide you want it to be


change your_button_name to the instance of that particular picture and insert that code into the actions panel, obviously changing the values of the your_button_name.x and .y to your preferred x and y positions...

m282
02-16-2011, 12:41 PM
object1.addEventListener(MouseEvent.CLICK, Move);
object2.addEventListener(MouseEvent.CLICK, Move);
object3.addEventListener(MouseEvent.CLICK, Move);

function Move($e:MouseEvent):void
{
$e.target.x = 200;
$e.target.y = 150;
}

This is just to put you on the right track.

Thanks for the code I will test it :)

eacode
02-19-2011, 05:49 PM
thomas 199992 said what you asked, $e.target is different