5 Replies Latest reply on Jun 5, 2009 9:59 AM by Michael Borbor

    Button Click Event Not Working

    JeffHung
      I'm a newbie to Flex. What I'm trying to do is to make a button when clicked, it prints some string. I like the code to be inside a class, if possible. This is the code I'm using. When the button is clicked, the event I set is not fired. Any help will be appreciated.
      ==============================================
      Y.mxml
      ==============================================
      <?xml version="1.0" encoding="utf-8"?>
      <mx:Application
      xmlns:mx=" http://www.adobe.com/2006/mxml"
      xmlns:custom="Y.*"
      layout="absolute"
      width="411" height="208">
      <custom:MyButton id="myButton" label="xyz" x="10" y="10" width="165" height="56" />
      </mx:Application>
      ==============================================
      MyButton.as
      ==============================================
      package Y
      {
      import flash.events.MouseEvent;
      import mx.controls.Button;
      import mx.events.FlexEvent;
      import mx.controls.Alert;

      public class MyButton extends Button
      {
      public var myButton:Button;

      public function MyButton()
      {
      super();

      addEventListener(
      FlexEvent.CREATION_COMPLETE,
      creationCompleteHandler
      );

      myButton = new Button();
      }

      private function creationCompleteHandler(event:FlexEvent):void
      {
      myButton.addEventListener(MouseEvent.CLICK, myClickHandler,true);
      }

      public function myClickHandler(event:MouseEvent):void
      {
      Alert.show("myClickHandler");
      dispatchEvent(event);
      }
      }
      }
      ==============================================