2 Replies Latest reply on Nov 9, 2006 9:52 PM by dbrady010

    Nubee: Help with Events

    dbrady010
      Hi

      I'm trying to get my head round events in Flex and I am having trouble getting my application to respond to a custom event. I have a simple ATM like number panel component where the user enters a PIN number which gets validated, and then an event is dispatched. My main application doesn't respond to it though. I know I'm doing something obviously wrong, but I can't spot it.

      Code excerpts...

      Custom event...

      package com.freepos.events
      {
      import flash.events.Event;

      public class LoginEvent extends Event {

      public static const LOGIN:String = "login";
      public var user:XML;

      public function LoginEvent(user:XML) {
      super(LOGIN);
      this.user = user;
      }
      }
      }

      PinPanel component...

      <?xml version="1.0" encoding="utf-8"?>
      <mx:Panel xmlns:mx=" http://www.adobe.com/2006/mxml" layout="absolute" width="284" height="440" title="Enter PIN">

      <mx:Metadata>
      [Event(name="login", type="com.freepos.events.LoginEvent")]
      </mx:Metadata>

      ...SNIP...

      private function handleVerifyPinResult(event:ResultEvent):void {
      var result:Object = event.result;
      dispatchEvent(new LoginEvent(XML(result)));
      }

      And the application has this...

      private function applicationComplete():void {
      addEventListener(LoginEvent.LOGIN, successfullLogin);
      }

      public function successfullLogin(event:LoginEvent):void {
      user = event.user;
      statusLabel.text = user.toString();
      currentState = 'UserLoggedIn';
      }

      Application complete is called and the listener added but successfullLogin is never called.

      Thanks for any pointers?

      Donald