Search code examples
apache-flexmate

Mate Dispatcher tag


I need to pass a variable in dispatcher tag... for instance

var google:EventName = new EventName(EventName.ADD_User,user);
dispatchEvent(google);

Now when i go to Mate dispatcher tag... how can i pass the value user.

  <mate:Dispatcher id="myDispatcher" generator="{EventName}" 
type="{EventName.ADD_User}">
                      <mate:eventProperties>
                                       <mate:EventProperties
                                                          myProperty="myValue"
                                                          myProperty2="100" />
                      </mate:eventProperties>
    </mate:Dispatcher>

Now how can i pass the user in the mate dispatcher tag.


Solution

  • You would have to declare user as a property of your GoogleEvent.as class. For GoogleEvent.as:

    package
    {
      public class GoogleEvent extends Event
      {
        public static const ADD_User:String = "GoogleEvent_AddUser";
    
        public var user:String;
    
        public function GoogleEvent(type:String, bubbles:Boolean=true, cancelable:Boolean=false)
        {
          super(type, bubbles, cancelable);
        }
      }
    }
    

    And in your event declaration:

    var google:GoogleEvent= new GoogleEvent(GoogleEvent.ADD_User);
    
    google.user = "My User's Name";
    dispatchEvent(google);
    

    Then to get the user value from your event in your Event Map:

    <EventHandlers type="{ GoogleEvent.ADD_User }">
      <MethodInvoker generator="{ MyTargetPresentaionModel }" method="DoSomething" arguments="{ [event.user] }" />
    </EventHandlers>
    

    Let me know if you have any questions. I hope this helps!