1 Reply Latest reply on Apr 5, 2007 6:01 AM by iquaaani

    Event Listeners

    iquaaani
      Hi Folks,

      I have this kind of problem where i have created simple class for showing bitmaps. I created object out of my class and now i want to use mouse event / buttons to trigger some actions but i'm not sure that what is the right way to do it.
      example follows:

      Class looks like:

      public class LBitmap2 extends Sprite
      {
      private var url:String;
      private var _loader:Loader = new Loader();
      private var image:Bitmap;

      public function LBitmap2 (url:String) {
      _loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onComplete);
      _loader.load(new URLRequest(url));
      }
      private function onComplete(event:Event):void
      {
      var image:Bitmap = Bitmap(_loader.content);
      var bitmap:BitmapData = image.bitmapData;

      addEventListener(MouseEvent.CLICK,clickHandler);
      }
      //How to lauch this event from e.g button
      public function clickHandler(event:MouseEvent):void
      {
      addChild(image);
      }

      All this works fine for me exept how to launch clickHandler event after i have created object like
      var pitmapp:LBitmap2 = new LBitmap2("Samples/image.jpg");

      i want to link clickHandler function to button e.g

      <mx:Button x="548" y="50" label="Show Pic" id="myBtn" click="clickHandler(event);" />
      This gives me an error: Call to a possibly undefined method clickHandler.

      What is the correct solution to handle this event ?