Copy link to clipboard
Copied
Hello!
I kinda need help with a project. I´m supposed to make a script that responds on a click and moves the circle from one rectangle to the another one.
(Here is a picture)
So, what I want is: When I click on the right blue rectangle the circle should instantly move inside the right rectangle. And same thing on the opposite way.
Thanks in advance!
- Best regards,
Aleksandar "Dyxir" B.
import flash.events.MouseEvent;
leftRec.addEventListener(MouseEvent.CLICK,fCircle);
rightRec.addEventListener(MouseEvent.CLICK,fCircle);
function fCircle(evt:MouseEvent)
{
circle.x=evt.currentTarget.x;
circle.y=evt.currentTarget.y;
}
Note: Registration point for all : center
Copy link to clipboard
Copied
import flash.events.MouseEvent;
leftRec.addEventListener(MouseEvent.CLICK,fCircle);
rightRec.addEventListener(MouseEvent.CLICK,fCircle);
function fCircle(evt:MouseEvent)
{
circle.x=evt.currentTarget.x;
circle.y=evt.currentTarget.y;
}
Note: Registration point for all : center
Copy link to clipboard
Copied
Seriously dude, thanks in a million!:) Answered after ~10minutes, wow!
Copy link to clipboard
Copied
Actually, from display list stand point, this code doesn't move circle inside square but just puts it over the square. The code below does move circle inside the clicked square:
leftRec.addEventListener(MouseEvent.CLICK,fCircle);
rightRec.addEventListener(MouseEvent.CLICK,fCircle);
function fCircle(e:MouseEvent)
{
DisplayObjectContainer(e.target).addChild(circle);
}
Find more inspiration, events, and resources on the new Adobe Community
Explore Now