4 Replies Latest reply on Feb 24, 2012 4:26 AM by Carnoldo

    [HELP] Target o currentTarget.

    Carnoldo

      I need help.


      I have a panel within the've put a canvas within the canvas I have two images (Image).


      I want to do the following:

      - When I select an image, change the type of courses and by pressing a click inside thecanvas and move the image up there.


      When I position myself on a picture and I click I get the result that the currentTarget is thecanvas and I want it to be the image.


      I hope I can help.

       

       

       

      private var p:Panel = new Panel();

      private var c:Canvas = new Canvas();  

       

      private function init(): void

      {

       

        c.id = "canvas";

                                              p.id = "panel";

       

                                              var b1:Image = new Image();

                                              b1.source = 'imagenes/img1.jpg';

                                              b1.width = 50;

                                              b1.height = 50;

                                              b1.id = "img1";

                                              b1.name = "img1";

       

                                              var b2:Image = new Image();

                                              b2.source = 'imagenes/img2.jpg';

                                              b2.width = 25;

                                              b2.height = 25;

                                              b2.id = "img2";

                                              b2.name = "img2";

       

                                              c.width = 700;

                                              c.height = 400;

       

                                              p.addChild(c);

                                              c.addChild(b1);

                                              c.addChild(b2);

       

        this.addElement(p);

                                              c.addEventListener(MouseEvent.MOUSE_OVER, mouseOver2);

                                              b1.addEventListener(MouseEvent.MOUSE_OVER, mouseOver);

                                              b2.addEventListener(MouseEvent.MOUSE_OVER, mouseOver);

       

                                              c.addEventListener(MouseEvent.CLICK, mouseClick2);

                                              b1.addEventListener(MouseEvent.CLICK, mouseClick);

                                              b2.addEventListener(MouseEvent.CLICK, mouseClick);

      }

       

      private function mouseOver2(e:MouseEvent):void

                                    {

                                              trace ("Over: " + new Date().toString() + " Target: " + e.target + " CurrentTarget: " + e.currentTarget.id );

                                    }

       

                                    private function mouseClick2(e:MouseEvent):void

                                    {

                                              trace("Click: " + new Date().toString() + " Target: " + e.target + " CurrentTarget: " + e.currentTarget.id );

                                    }

        • 1. Re: [HELP] Target o currentTarget.
          Sathyamoorthi Level 2

          e.target always returns the object that is crrently targeted.

           

          if you click on image e.target will return image.

           

          if you click on canvas e.target will return canvas.

           

          c.addEventListener(MouseEvent.CLICK, mouseClick2)

           

            private function mouseClick2(e:MouseEvent):void

              {

                           if(event.target is image)

                              {

                                        trace(event.target);

                               }

              }

          • 2. Re: [HELP] Target o currentTarget.
            Carnoldo Level 1

            When I click on an image, if it does not work.

             

            c1.addEventListener(MouseEvent.CLICK, mouseClick2);

             

            private function mouseClick2(e:MouseEvent):void

                                          {

                                                    if (e.target is Image){

                                                              trace ("Is image: " + e.target);

                                                    }

                                                    trace("Click: " + new Date().toString() + " Target: " + e.target + " CurrentTarget: " + e.currentTarget.id );

                                          }

             

             

            Result:

            Click: Fri Feb 24 10:08:49 GMT-0200 2012 Target: aplicacion.ApplicationSkin7._ApplicationSkin_Group1.contentGroup.panel.canvas.img1.FlexLo ader12 CurrentTarget: canvas

            Click: Fri Feb 24 10:08:49 GMT-0200 2012 Target: aplicacion.ApplicationSkin7._ApplicationSkin_Group1.contentGroup.panel.canvas.img1.FlexLo ader12 CurrentTarget: canvas

             

            Why FlexLoader12?


            • 3. Re: [HELP] Target o currentTarget.
              Sathyamoorthi Level 2

              i am not really sure about FlexLoader12. did you customize your image component.

               

              but 'event.target.parent' will solve your issue

              • 4. Re: [HELP] Target o currentTarget.
                Carnoldo Level 1

                Thank you so much!, Now work for me.