1 Reply Latest reply on Nov 2, 2010 10:11 AM by Flex harUI

    Can't determine event target

    wilsonsilva7 Level 1

      I have a Canvas whose id is workarea. workarea has a UIComponent child named scene. scene will contain lots of Sprites.

       

      <?xml version="1.0" encoding="utf-8"?>

      <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="main();">

      <mx:Script>

       

      <![CDATA[

       

      import mx.core.UIComponent;

       

      private var scene:UIComponent;

       

      private function main():void {

       

          scene = new UIComponent;

          workarea.addChild(scene);

       

          var square:Sprite = new Sprite();

          scene.addChild(square);

                

          var rectangle:Sprite = new Sprite();

          scene.addChild(rectangle);

                 

          square.graphics.beginFill(0xFFFCC4, 1);

          square.graphics.drawRect(50, 10, 64, 64);

          square.graphics.endFill();

                 

          rectangle.graphics.beginFill(0x6B0933, 1);

          rectangle.graphics.drawRect(80, 100, 64, 128);

          rectangle.graphics.endFill();

       

          scene.addEventListener(MouseEvent.MOUSE_DOWN, onMouseDown);

          scene.addEventListener(MouseEvent.MOUSE_UP, onMouseUp);

       

      }

       

      private function onMouseDown(e:MouseEvent):void {

                 

          if (e.target != scene) {

              e.target.startDrag();

          } else {

              trace("I didn't click over the scene!"); // this line is never executed

          }           

                 

      }

       

      private function onMouseUp(e:MouseEvent):void {

          e.target.stopDrag();

      }

       

       

      ]]>

      </mx:Script>

       

      <mx:Canvas id="workarea" backgroundColor="#E0CC70" width="494" height="372" x="108.5" y="94">

      </mx:Canvas>

       

      </mx:Application>

       

      When I click over a Sprite I want to be able to drag it. But when I click on the scene I want to do something else. My problem is that the line between the else brackets is never executed and I have no clue why.

       

       

      Here's the source (298 Kb): http://www.2shared.com/file/Zn1QaN6V/Sample.html