flash用右键菜单来控制显示、隐藏右键菜单

王朝other·作者佚名  2008-05-19
窄屏简体版  字體: |||超大  

这贴的特色在于:用右键菜单来控制显示、隐藏右键菜单!

抛开实际用途不谈,这贴主要有助于对两个类中的属性和方法加深理解!

注:可用性 Flash Player 7

将代码直接复制到第一帧即可:

代码//

// 函数:当点击指定菜单项时,显示所有内置菜单项

// 参数:

// currentObject 对右键点击对象的引用

// itemReference 对选定 ContextMenuItem 对象的引用

//

function showBuiltInItems(currentObject:Object, itemReference:ContextMenuItem):Void {

// 临时存储自定义菜单项的路径

var temporaryCustomItems = currentObject.menu.customItems;

for (var everyProp in temporaryCustomItems) {

temporaryCustomItems[everyProp]["enabled"] = true;

}

// 选中项变为不可用

itemReference.enabled = false;

// 临时存储内建菜单项的路径

var temporaryBuiltInItems = currentObject.menu.builtInItems;

// 通过 for..in 循环枚举 ContextMenu 类的 temporaryBuiltInItems 对象的属性,即内置菜单项的所有名称

for (var eachProp in temporaryBuiltInItems) {

// 输出属性名

//trace(eachProp);

// 改变各属性值为true,即显示

temporaryBuiltInItems[eachProp] = true;

}

}

//

// 函数:当点击指定菜单项时,隐藏所有内置菜单项

//

function hideBuiltInItems(currentObject:Object, itemReference:ContextMenuItem):Void {

// 临时存储自定义菜单项的路径

var temporaryCustomItems = currentObject.menu.customItems;

for (var everyProp in temporaryCustomItems) {

temporaryCustomItems[everyProp]["enabled"] = true;

}

// 选中项变为不可用

itemReference.enabled = false;

// 隐藏所有内置菜单项

currentObject.menu.hideBuiltInItems();

}

//

// 创建一个 ContextMenu 类的对象

var firstContextMemu:ContextMenu = new ContextMenu();

// 隐藏指定 ContextMenu 对象中的所有内置菜单项(“设置”除外)

firstContextMemu.hideBuiltInItems();

// 添加新的菜单项

firstContextMemu.customItems.push(new ContextMenuItem("显示菜单", showBuiltInItems));

firstContextMemu.customItems.push(new ContextMenuItem("隐藏菜单", hideBuiltInItems, true, false));

// 将 ContextMenu 对象会应用到根时间轴(或者其他指定的对象)

_root.menu = firstContextMemu;

/*

// 查看 firstContextMemu.customItems 内容

for (var k in firstContextMemu.customItems) {

for (var n in firstContextMemu.customItems[k]) {

trace(firstContextMemu.customItems[k][n]);

}

}

*/

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
 
© 2005- 王朝網路 版權所有 導航