Skip to main content
Srihari_Ch
Known Participant
June 24, 2009
Question

Problem with MouseEvent.CLICK and visibility of Sprite object

  • June 24, 2009
  • 2 replies
  • 486 views

Hi all,

             I am loading an image using Loader object dynamically on the stage.It works fine.

            Here, my loader instance name is: myLoader.  When I click on the dynamically loaded image, I need to place a small red rectangle at that particular pixel position on the image.

           For creating a small rectangle, I am using following code:

var redRect:Sprite = new Sprite();

redRect.graphics.beginFill(0xff0000);

redRect.graphics.drawRect(evnt.localX,evnt.localY,7,7);

addChild(redRect);

trace("redRect.visible: "+redRect.visible);

        My requirement is as follows:

           Whenever I click on this loaded image for first time, I need to display the redRect(rectangle which is red in color, which is of Sprite type) over that pixel-position(say, at old_x,old_y coordinates) where I have clicked.

           Now, if I click on the same image for the second time (at a different pixel-position), then the redRect which is already displayed must be made hidden and the redRect must be created(displayed) at new pixel-position(i.e., at new_x,new_y) and made visible and so on.

         Hence, in this way,  We need to display the redRect at latest/newly captured pixel-position and must be invisible at all earlier/former/old pixel-positions.

      How to solve my issue? It is creating a huge problem for me to solve this.

Please, can any one reply me the solution for this above issue by sparing 2 minutes of your valuable time in filling this gap of my work.

Thanks in advance....

Waiting for yor replies..

Srihari.Ch         

This topic has been closed for replies.

2 replies

Harvolev
Participating Frequently
June 24, 2009

Basically what the user above mentioned, just wanted to be more specific:

try using:

evnt.mouseX, evnt.mouseY

for the position of the click instead.

June 24, 2009

Hi,

If I understand your problem, you can just:

  1. Create and addChild your redRect once up front
  2. In the Click eventhandler set x and y value of redRect to x and y value of the mouse.

Joergen