2007年9月28日 @ 14:55
ContextMenuManager
ContextMenuManager
I dont like the way we create and modify items with ContextMenu class in ActionScript 3.0, first we have to create item, then add event listener, then push our item to ContextMenu.customItems, I think this is quite alot of code for simple task. And there is one more disadvanage, we cannot subclass ContextMenu items, this means we cannot create subclass which would add some items by default.
All this inspired me to create my own class which would manage ContextMenu instance. Then I’ve added methods like remove, insert, getItem.
Take a look on the code below, this code creates new item in new ContextMenu instance.
var myContextMenu:ContextMenu = new ContextMenu();
myContextMenu.hideBuiltInItems();
var item:ContextMenuItem = new ContextMenuItem("My Caption");
item.addEventListener(ContextMenuEvent.MENU_ITEM_Select,myHandler);
myContextMenu.customItems.push(item);
myInteractiveObject.contextMenu = myContextMenu;
If we want to add second item, get read for 3 more lines of code, and what about 5, 10 items?. I want to do this task like this:
var cmm:CMManager = new CMManager(myInteractiveObject);
cmm.add("My Caption",myHandler);
That’s all folks, now lets think about something more complex, what if we want to create different type of controls, with different ContextMenu’s, but we also want all ContextMenu’s to have “About My Application” item. This is simple, just subclass CMManager:
package
{
import eu.orangeflash.managers.CMManager;
import flash.display.InteractiveObject;
import flash.ui.ContextMenu;
import flash.events.ContextMenuEvent;
public class MyCMM extends CMManager
{
public function MyCMM(target:InteractiveObject)
{
super(target);
add("About My Super Application",traceAbout);
}
private function traceAbout(event:ContextMenuEvent):void
{
trace("My Supper App");
}
}
}
2007年9月14日 @ 22:42
Flex 學習資源更新
Flex 學習資源更新
最近由於種種緣故又要開始做點教育訓練的事,先趁現在有空把手邊的資料整理一下。
*Flex 的基礎架構
關於 flex 基本上常被問到的不外乎就是「如何可以學好它?」,要瞭解這個問題的答案基本上只要看懂下面這圖就ok了。



