ResponseAnnouncer

(This tag must be placed inside an <EventHandlers> tag or a <MessageHandlers> tag)

This tag has been deprecated, please use CallBack instead.

The ResponseAnnouncer tag is placed inside an EventHandlers block, so that when an object dispatches an event, and the list of handlers runs, this tag will allow you to send responses directly to the object that dispatched the event. These responses are actually custom events that you need to create. Using the ResponseAnnouncer tag is very similar in form and purpose of the EventAnnouncer tag, with the important difference that when using the EventAnnouncer tag, all listeners of that event will be notified, whereas when using the ResponseAnnouncer tag, only the object that dispatched the original event will be notified.

Example:

<EventHandlers type="myEventType">

   <ResponseAnnouncer generator="MyEventClass" type="myEventType">
      
      <Properties myProperty="myValue" myProperty2="100"/>

   </ResponseAnnouncer>

</EventHandlers>

The use of this tag will have no effect if the original event was not dispatched using the Dispatcher tag. Moreover, this tag will have no effect if no ResponseHandler tag was added as an inner tag to the Dispatcher tag.

For a more in-depth description of attributes and inner tags, see EventAnnouncer.

Attributes

type

required

The type of the event to generate as the response. This type is the one that the <ResponseHandler> tag will listen to. See <ResponseHandler> for more information.

generator

The event class to instantiate. If this attribute is not specified a DynamicEvent will be generated.

constructorArguments

Array

If your event has a constructor signature that differs from the default Flash Event constructor, you need to specify the parameters with this attribute.

Using a custom event

Using a custom event gives the most control over what you send as a response. You can set any properties on that event with data coming from various places such as the result of a server call. When the ResponseHandler gets this response in the form of a custom event, its handler will know what properties to look for in this event.

To send a custom event as a response, you specify the generator attribute to point to your custom event class. Both the class and event type can be specified using bindings:

<ResponseAnnouncer generator="{MyEventClass}" type="{MyEventClass.MY_EVENT_TYPE}">
   
   <Properties myProperty="myValue" myProperty2="100"/>

</ResponseAnnouncer>

Using a DynamicEvent

If you don't want to create a custom event only to receive a response, you can use a DynamicEvent. You do so by simply not specifying any generator. You must still supply the event type, which can be a simple string. You just need to ensure that the event type matches exactly that one specified by the <ResponseHandler> in the view. You can set any property to this dynamic event. In the view, you will receive this dynamic event, and while you will be able to get to the properties you set, you won't be able to get compiler errors if you make mistakes in the names of the properties you are trying to access.

<ResponseAnnouncer type="myEventType">
   
   <Properties myProperty="myValue" myProperty2="100"/>

</ResponseAnnouncer>

1 response

  1. This is an interesting feature. This is exactly why I had difficulty with Cairngorm reaching back to the view that dispatched the event.

Comments now closed