2 Replies Latest reply on Nov 17, 2009 10:42 PM by ShardulSingh

    How to get the image id and source on Click

    al7iss

      Hi, I have an image to which I added a mouse click event listener and I want to get the id or/and source of the image on click but it is not working.

      Thanks

       

      here is my code:

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

      <?xml version="1.0"?>

       

      <mx:Application

       

       

      xmlns:mx="http://www.adobe.com/2006/mxml" applicationComplete="init();"

      >

       

       

       

      <mx:Script>

      <![CDATA[

       

       

       

      import mx.controls.Image;

       

       

      import mx.controls.Alert;

       

       

       

      public function init():void

      {

       

       

      var

      xx:int=40;

       

       

      var b:Image=new Image();

      b.id=

      "image id";

      b.source=

      "image.jpg";

      b.addEventListener(MouseEvent.CLICK, f);

      b.x=xx;

      p.addChild(b);

      }

       

       

       

       

      function f(e:MouseEvent):void

      {

       

       

      var b:Image=e.target as Image;

      Alert.show(b.id);

      Alert.show(String(b.source));

      }

      ]]>

       

       

      </mx:Script>

       

       

      <mx:Canvas width="444"

      height="

      348"

      id="

      p"

      >

       

       

      </mx:Canvas>

       

      </mx:Application>