Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Need help with Sprite´s. (Rectangles and Circle)

New Here ,
Oct 04, 2010 Oct 04, 2010

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)

howtosprite.JPG

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.

TOPICS
ActionScript
553
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Deleted User
Oct 04, 2010 Oct 04, 2010

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

Translate
Guest
Oct 04, 2010 Oct 04, 2010

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Oct 04, 2010 Oct 04, 2010

Seriously dude, thanks in a million!:) Answered after ~10minutes, wow!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Oct 04, 2010 Oct 04, 2010
LATEST

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines