I want to have a single event listener for multiple events and depending on the
type of event i want to handle them separately.
Something similar to Swiz framework see: ‘Handling Multiple Events from a Single Method’
i have a piece of code like
var toolOptions:UIComponent=ToolOptions.createToolOptions(type);
if (options != null)
{
options.addEventListener(Event.SELECT,toolOptionSelectedHandler);
someViewComponent.addOptions(toolOptions);
}
// handle depending on event type
private function toolOptionSelectedHandler(event:*):void
{
//handle depending on type of event fired
// type cast event depending on type and retrieve VO from event
//and send handle it..
//SomeToolObj.handle(event.VO);
}
In above toolOptions is a mxml component which get dynamically created based on
‘type’.
Also which type of event should be dispatch the event from the component? eg: Event.SELECT
To be more precise the above is basically required for a toolbar.
When user selects a tool,he is shown options for a tool and when he selects options,
tool should apply them to object on the view.
Is there a better way to do the same?
That’s what I understand:
You have different tools. Each of the tools has a list of options. You click an option, and a single event handler should perform some action depending on the option.
Create a custom event
OptionEvent.SELECTwith the propertyoptionType.When the user selects the option, dispatch the event like this:
Listen to the event like you do:
Distinguish the type of option by determining the option type:
UPDATE – How to set up a list of option values in OptionEvent: