[flexcoders] Why MouseEvent.Click Event doesn't work

2008-04-05 Thread mouhong.lin

Hi, I'm a Flex beginner.

Here I want a shape(_shape) to move while I'm clicking another
shape(_goRight).

ActionScript Code:

public class Move extends Sprite
  {
   private var _goLeft:Shape;
   private var _goRight:Shape;
   private var _shape:Shape;
   private var _sprite:Sprite;

   public function Move()
  {
_goRight = new Shape();
_goRight.graphics.lineStyle(2, 0xff);
_goRight.graphics.beginFill(0);
_goRight.graphics.lineTo(30, 15);
_goRight.graphics.lineTo(0, 30);
_goRight.graphics.lineTo(0, 0);
_goRight.graphics.endFill();

_shape = new Shape();
_shape.graphics.lineStyle(2, 0xff);
_shape.graphics.beginFill(0);
_shape.graphics.drawRoundRect(0, 100, 50, 30, 5, 5);
_shape.graphics.endFill();


   //add event listener
_goRight.addEventListener(MouseEvent.CLICK, onLeftClick);

this.addChild(_goRight);
this.addChild(_shape);

  }

   private function onLeftClick(event:MouseEvent):void
  {
   _shape.x += 5;
  }

}

But when I click shape _goRight, nothing happens. Why? I need a help!



RE: [flexcoders] Why MouseEvent.Click Event doesn't work

2008-04-05 Thread Alex Harui
Shapes are not InteractiveObjects so they don't emit mouse events.  Use
Sprite instead

 



From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] On
Behalf Of mouhong.lin
Sent: Saturday, April 05, 2008 10:51 AM
To: flexcoders@yahoogroups.com
Subject: [flexcoders] Why MouseEvent.Click Event doesn't work

 

Hi, I'm a Flex beginner.

Here I want a shape(_shape) to move while I'm clicking another
shape(_goRight).

ActionScript Code:

public class Move extends Sprite
 {
  private var _goLeft:Shape;
  private var _goRight:Shape;
  private var _shape:Shape;
  private var _sprite:Sprite;
  
  public function Move()
 {
   _goRight = new Shape();
   _goRight.graphics.lineStyle(2, 0xff);
   _goRight.graphics.beginFill(0);
   _goRight.graphics.lineTo(30, 15);
   _goRight.graphics.lineTo(0, 30);
   _goRight.graphics.lineTo(0, 0);
   _goRight.graphics.endFill();

   _shape = new Shape();
   _shape.graphics.lineStyle(2, 0xff);
   _shape.graphics.beginFill(0);
   _shape.graphics.drawRoundRect(0, 100, 50, 30, 5, 5);
   _shape.graphics.endFill(); 
   

  //add event listener
   _goRight.addEventListener(MouseEvent.CLICK, onLeftClick);

   this.addChild(_goRight);
   this.addChild(_shape);

 }
  
  private function onLeftClick(event:MouseEvent):void
 {
  _shape.x += 5;
 }

}

But when I click shape _goRight, nothing happens. Why? I need a help!