代码
var myContextMenu:ContextMenu = new ContextMenu();
//声明菜单新项
var item:ContextMenuItem = new ContextMenuItem("Hello World");
//添加到菜单显示项目数组
myContextMenu.customItems.push(item);
this.contextMenu = myContextMenu;
//点击按钮引发该事件
item.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT, mouseRelease);
function mouseRelease(event:ContextMenuEvent)
{
var txtField:TextField = new TextField();
txtField.text = "Hello World";
addChild(txtField);
}
//声明菜单新项
var item:ContextMenuItem = new ContextMenuItem("Hello World");
//添加到菜单显示项目数组
myContextMenu.customItems.push(item);
this.contextMenu = myContextMenu;
//点击按钮引发该事件
item.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT, mouseRelease);
function mouseRelease(event:ContextMenuEvent)
{
var txtField:TextField = new TextField();
txtField.text = "Hello World";
addChild(txtField);
}
代码
代码
//测试类:TestContextMenu
package com.util
{
import flash.display.Sprite;
import flash.events.ContextMenuEvent;
import flash.text.TextField;
import flash.ui.ContextMenuItem;
import com.util.ContextMenuPlus;
import flash.net.navigateToURL;
import flash.net.URLRequest;
public class TestContextMenu extends Sprite
{
private var txt:TextField;
private var answerObj:Object = new Object();
private var txtColorObj:Object = new Object();
private var borderColorObj:Object = new Object();
public function TestContextMenu()
{
initTxt();
initObj();
initCm();
}
private function initTxt():void
{
txt = new TextField();
txt.text = "ok";
txt.width = 200;
txt.x = 50;
txt.y = 20;
txt.border = true;
txt.borderColor = 0x006699;
txt.height = 60;
txt.wordWrap = true;
this.addChild(txt);
}
private function initObj():void
{
answerObj["母亲节是哪天?"] = "五月的第二个星期日";
answerObj["父亲节是哪天?"] = "六月的第三个星期日";
txtColorObj["红色文字"] = 0xFF0000;
txtColorObj["蓝色文字"] = 0x0000FF;
txtColorObj["黑色文字"] = 0x000000;
borderColorObj["绿色边框"] = 0x00FF00;
borderColorObj["紫色边框"] = 0x8000FF;
borderColorObj["黑色边框"] = 0x000000;
}
private function initCm():void
{
var cm:ContextMenuPlus = new ContextMenuPlus(true, onShowAnswer, "母亲节是哪天?", "父亲节是哪天?");
contextMenu = cm.contextMenu;
cm.addCustom(onGetUrl, "eidiot's blog", true);
cm.addGroup(onSetBorderColor, true, "绿色边框", "紫色边框", "黑色边框");
txt.contextMenu = new ContextMenuPlus(true, onSetTxtColor, "红色文字", "蓝色文字", "黑色文字").contextMenu;
}
private function onShowAnswer(e:ContextMenuEvent):void
{
txt.text = "问 : " + e.currentTarget.caption + " \t答 : " + answerObj[e.currentTarget.caption];
}
private function onSetTxtColor(e:ContextMenuEvent):void
{
txt.textColor = txtColorObj[e.currentTarget.caption];
}
private function onSetBorderColor(e:ContextMenuEvent):void
{
txt.borderColor = borderColorObj[e.currentTarget.caption];
}
private function onGetUrl(e:ContextMenuEvent):void
{
navigateToURL(new URLRequest("http://eidiot.net"), "_blank");
}
}
}
//测试类:TestContextMenu
package com.util
{
import flash.display.Sprite;
import flash.events.ContextMenuEvent;
import flash.text.TextField;
import flash.ui.ContextMenuItem;
import com.util.ContextMenuPlus;
import flash.net.navigateToURL;
import flash.net.URLRequest;
public class TestContextMenu extends Sprite
{
private var txt:TextField;
private var answerObj:Object = new Object();
private var txtColorObj:Object = new Object();
private var borderColorObj:Object = new Object();
public function TestContextMenu()
{
initTxt();
initObj();
initCm();
}
private function initTxt():void
{
txt = new TextField();
txt.text = "ok";
txt.width = 200;
txt.x = 50;
txt.y = 20;
txt.border = true;
txt.borderColor = 0x006699;
txt.height = 60;
txt.wordWrap = true;
this.addChild(txt);
}
private function initObj():void
{
answerObj["母亲节是哪天?"] = "五月的第二个星期日";
answerObj["父亲节是哪天?"] = "六月的第三个星期日";
txtColorObj["红色文字"] = 0xFF0000;
txtColorObj["蓝色文字"] = 0x0000FF;
txtColorObj["黑色文字"] = 0x000000;
borderColorObj["绿色边框"] = 0x00FF00;
borderColorObj["紫色边框"] = 0x8000FF;
borderColorObj["黑色边框"] = 0x000000;
}
private function initCm():void
{
var cm:ContextMenuPlus = new ContextMenuPlus(true, onShowAnswer, "母亲节是哪天?", "父亲节是哪天?");
contextMenu = cm.contextMenu;
cm.addCustom(onGetUrl, "eidiot's blog", true);
cm.addGroup(onSetBorderColor, true, "绿色边框", "紫色边框", "黑色边框");
txt.contextMenu = new ContextMenuPlus(true, onSetTxtColor, "红色文字", "蓝色文字", "黑色文字").contextMenu;
}
private function onShowAnswer(e:ContextMenuEvent):void
{
txt.text = "问 : " + e.currentTarget.caption + " \t答 : " + answerObj[e.currentTarget.caption];
}
private function onSetTxtColor(e:ContextMenuEvent):void
{
txt.textColor = txtColorObj[e.currentTarget.caption];
}
private function onSetBorderColor(e:ContextMenuEvent):void
{
txt.borderColor = borderColorObj[e.currentTarget.caption];
}
private function onGetUrl(e:ContextMenuEvent):void
{
navigateToURL(new URLRequest("http://eidiot.net"), "_blank");
}
}
}