I'm using a Menu control. Normally I'd catch the Menu's control event and then 
act on whatever selection the user made with something like a switch block.

But I wanted to see if I could be more clever and embed the function name and 
parameters in the XML Menu data provider itself, like this:

<mx:XML id="xmlFormMenuOptions" >
  <Menu id="MenuOptions">
    <menuitem id="AddNewChartMenuOption" label="Add Chart..." 
callback="AddNewChartButton_click" arguments="" />
    <menuitem id="RenameChartMenuOption" label="Rename Chart..." 
callback="PopUpTextBox" arguments="RenameChart, RenameChartButtonTextBox, 
{nameChartSelected}" enabled="{selectedChartingPanelTableCell}" />
    <menuitem id="DeleteChartMenuOption" label="Delete Chart" 
callback="PopUpCheckBox" arguments="DeleteChart, DeleteChartButtonCheckBox" 
enabled="{selectedChartingPanelTableCell}" />
    <menuitem id="RaiseChartOrderMenuOption" label="Raise Chart Order" 
callback="RaiseChartOrderButton_click" arguments="" 
enabled="{RaiseChartOrderButton.enabled}" />
    <menuitem id="LowerChartOrderMenuOption" label="Lower Chart Order" 
callback="LowerChartOrderButton_click" arguments="" 
enabled="{LowerChartOrderButton.enabled}" />
    <menuitem id="OpenAlertsWindowMenuOption" label="Open Alerts Window" 
callback="ProjectProperties.setValue" arguments="ShowAlertsWindow, true" />
    <menuitem id="ChartingPanelWhatAmIMenuOption" label="What am I?" 
callback="PopUpMessage" arguments="ChartingPanelWhatAmIMenuOption, null   " />
    <menuitem id="HelpMenuOption" label="Help" callback="" />
  </Menu>
</mx:XML>

If you look at each <menuitem/> you'll see a 'callback' attribute and an 
'arguments' attribute. The arguments are comma-delineated that I need to parse 
into an Array and scrub: for example, by converting string references into real 
ones like this:

if( this.hasOwnProperty(arg) )
    arrayArguments[i] = this[arg];

I then have been successful in using the callLater function like this:

callLater(this[callback], arrayArguments);

So far so good - it works great!

But I've hit a tiny snag. If the function is in a foreign class then everything 
falls apart. For example, this won't work:

callback = "ProjectProperties.setValue"
arguments = "ShowAlertsWindow, true"

Because there is no such thing as this[ProjectProperties.setValue] the 
callLater function can't handle it. I can easily build a little stub but I'm 
hoping to keep things clean and elegant.

I've been searching for a way to call-by-name in Flex but haven't found one 
(except for callLater). Is there a way I can do this?


Reply via email to