Create Dynamic Menu with ActionScript 3.0 and Flex Reflection

I dealt with a completely dynamic menu lately. This menu;

1- Takes all items

2- Takes all display names

3- Takes all functions that will be triggered from the server side and

4- Executes the related functions by Reflection.

Server side returns me an XML like this:

And I am meeting this XML with an ActionScript object structured such as:

I first created a menu bar with a click handler function called “create”:

“create” function calls the remote object that returns me an XML I showed before. And set the stageX, stageY variables that will be used to position the menu.

I inserted all menu item contents to an Array Collection and assign to the menu as an Data Provider. On every menu item object in which is provided in Array Collection is labeled with the label property of the items. After filling the menu, I bound a click listener to the menu. This listener will execute a method by reflection (I mean the name of it.)

This reflection function is below: Here, MethodInvoker is a class to execute a function by its name and provided with “as3commons-reflect.swc”.  Here, “target” is the class that includes the desired function, “method” is the name of the method and it has the same name as the label of the menu item. Here, if we click the addUser item in the menu it will create a MenuEvent handled by “menuSelect” function.  It executes the “addUser” function by reflection.

That’s all. We can use this component to provide different menus to users with different credentials.

Bon appettite.

Yorum yapın

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Değiştir )

Twitter picture

You are commenting using your Twitter account. Log Out / Değiştir )

Facebook photo

You are commenting using your Facebook account. Log Out / Değiştir )

Connecting to %s

Follow

Get every new post delivered to your Inbox.