📄 glllmenu.as
字号:
package com.ll19.menu {
import flash.display.MovieClip;
import flash.events.ContextMenuEvent;
import flash.net.URLRequest;
import flash.net.navigateToURL;
import flash.ui.ContextMenu;
import flash.ui.ContextMenuBuiltInItems;
import flash.ui.ContextMenuItem;
import com.ll19.sound.GlllSound;
import com.ll19.util.GlllStringUtil;
/**
* - GL'LL. -
* 自定义右键菜单类实现IMenu
*
* @author <a href="http://www.LL19.com/">LL19.com</a>
*
*/
public class GlllMenu implements IMenu {
public var myMenu:ContextMenu;
private var defaultItems:ContextMenuBuiltInItems;
/**
* 构建菜单
* @param showMenu no屏蔽右键所有菜单,或者选择显示例如 print,zoom 则显示打印和放大缩小(用,隔开),只显示其中之一直接输入字符,有效字符包括“print,forwardAndBack,zoom,save,rewind,quality,play,loop” 若不构建传入"show".
* @param myObject this.
*/
function GlllMenu(showMenu:String,myObject:MovieClip) {
if (showMenu != "show") {
try {
myMenu = new ContextMenu();
defaultItems = myMenu.builtInItems;
if (showMenu == "no") {
myMenu.hideBuiltInItems();
myObject.contextMenu = myMenu;
}
else if (showMenu.indexOf(",") > -1) {
var menuList:Array = showMenu.split(",");
myMenu.hideBuiltInItems();
for (var i:int = 0;i < menuList.length; i++) {
switch (true) {
case GlllStringUtil.indexString(menuList[i], "print") :
//显示打印
defaultItems.print = true;
break;
case GlllStringUtil.indexString(menuList[i], "forwardAndBack") :
//显示前进后退
defaultItems.forwardAndBack = true;
break;
case GlllStringUtil.indexString(menuList[i], "zoom") :
//显示放大缩小
defaultItems.zoom = true;
break;
case GlllStringUtil.indexString(menuList[i], "save") :
//显示save
defaultItems.save = true;
break;
case GlllStringUtil.indexString(menuList[i], "rewind") :
//显示rewind
defaultItems.rewind = true;
break;
case GlllStringUtil.indexString(menuList[i], "quality") :
//显示quality
defaultItems.quality = true;
break;
case GlllStringUtil.indexString(menuList[i], "play") :
//显示play
defaultItems.play = true;
break;
case GlllStringUtil.indexString(menuList[i], "loop") :
//显示loop
defaultItems.loop = true;
break;
default:
trace("传入参数showMenu: " + menuList[i] + " 没有执行");
}
}
myObject.contextMenu = myMenu;
}
else if (showMenu.indexOf(",") == -1) {
myMenu.hideBuiltInItems();
switch (true) {
case GlllStringUtil.indexString(showMenu, "print") :
//显示打印
defaultItems.print = true;
break;
case GlllStringUtil.indexString(showMenu, "forwardAndBack") :
//显示前进后退
defaultItems.forwardAndBack = true;
break;
case GlllStringUtil.indexString(showMenu, "zoom") :
//显示放大缩小
defaultItems.zoom = true;
break;
case GlllStringUtil.indexString(showMenu, "save") :
//显示save
defaultItems.save = true;
break;
case GlllStringUtil.indexString(showMenu, "rewind") :
//显示rewind
defaultItems.rewind = true;
break;
case GlllStringUtil.indexString(showMenu, "quality") :
//显示quality
defaultItems.quality = true;
break;
case GlllStringUtil.indexString(showMenu, "play") :
//显示play
defaultItems.play = true;
break;
case GlllStringUtil.indexString(showMenu, "loop") :
//显示loop
defaultItems.loop = true;
break;
default:
trace("传入参数showMenu: " + showMenu + " 没有执行");
}
myObject.contextMenu = myMenu;
}
else {}
}
catch (e:Error) {
trace("构建菜单错误 myMc有否传入正确?");
trace(e.message);
throw e;
}
finally {
}
}
else {
myObject.contextMenu = myMenu;
}
}
/**
* 用来建立右键链接菜单
* @param title 链接的标题
* @param url 链接的地址
* @param separatorBefore 菜单项上方是否显示分隔条
*/
public function buildLinkMenu(title:String , url:String,ISeparatorBefore:Boolean):void {
var item:ContextMenuItem = new ContextMenuItem(title);
myMenu.customItems.push(item);
item.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT, mouseRelease);
item.separatorBefore = ISeparatorBefore;
function mouseRelease(event:ContextMenuEvent):void {
var request:URLRequest = new URLRequest(url);
navigateToURL(request, "_blank");
}
}
/**
* 用来建立右键文字菜单
* @param text 链接的文字
* @param separatorBefore 菜单项上方是否显示分隔条
*/
public function buildTextMenu(text:String,ISeparatorBefore:Boolean):void {
var item:ContextMenuItem = new ContextMenuItem(text);
item.separatorBefore = ISeparatorBefore;
myMenu.customItems.push(item);
}
/**
* 用来播放当前音乐
* @param text 链接的文字
* @param separatorBefore 菜单项上方是否显示分隔条
*/
public function playMusic(text:String, separatorBefore:Boolean):void {
var item:ContextMenuItem = new ContextMenuItem(text);
item.separatorBefore = separatorBefore;
myMenu.customItems.push(item);
item.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT, mouseRelease);
function mouseRelease(event:ContextMenuEvent):void {
GlllSound.playMusic();
}
}
/**
* 用来停止播放当前音乐
* @param text 显示文字
* @param separatorBefore 菜单项上方是否显示分隔条
*/
public function stopMusic(text:String, separatorBefore:Boolean):void {
var item:ContextMenuItem = new ContextMenuItem(text);
item.separatorBefore = separatorBefore;
myMenu.customItems.push(item);
item.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT, mouseRelease);
function mouseRelease(event:ContextMenuEvent):void {
GlllSound.stopMusic();
}
}
/**
* 用来播放下一首音乐
* @param text 显示文字
* @param separatorBefore 菜单项上方是否显示分隔条
*/
public function playNextMusic(text:String, separatorBefore:Boolean):void {
var item:ContextMenuItem = new ContextMenuItem(text);
item.separatorBefore = separatorBefore;
myMenu.customItems.push(item);
item.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT, mouseRelease);
function mouseRelease(event:ContextMenuEvent):void {
GlllSound.playNextMusic();
}
}
/**
* 用来播放上一首音乐
* @param text 显示文字
* @param separatorBefore 菜单项上方是否显示分隔条
*/
public function playPreviousMusic(text:String, separatorBefore:Boolean):void {
var item:ContextMenuItem = new ContextMenuItem(text);
item.separatorBefore = separatorBefore;
myMenu.customItems.push(item);
item.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT, mouseRelease);
function mouseRelease(event:ContextMenuEvent):void {
GlllSound.playPreviousMusic();
}
}
/**
* 用来关闭声音
* @param text 显示文字
* @param separatorBefore 菜单项上方是否显示分隔条
*/
public function closeVolume(text:String, separatorBefore:Boolean):void {
var item:ContextMenuItem = new ContextMenuItem(text);
item.separatorBefore = separatorBefore;
myMenu.customItems.push(item);
item.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT, mouseRelease);
function mouseRelease(event:ContextMenuEvent):void {
GlllSound.closeVolume();
}
}
/**
* 用来打开声音
* @param text 显示文字
* @param separatorBefore 菜单项上方是否显示分隔条
*/
public function openVolume(text:String, separatorBefore:Boolean):void {
var item:ContextMenuItem = new ContextMenuItem(text);
item.separatorBefore = separatorBefore;
myMenu.customItems.push(item);
item.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT, mouseRelease);
function mouseRelease(event:ContextMenuEvent):void {
GlllSound.openVolume();
}
}
/**
* 用来改变音乐波谱
* @param text 显示文字
* @param separatorBefore 菜单项上方是否显示分隔条
*/
public function changeMusicWave(text:String, separatorBefore:Boolean):void {
var item:ContextMenuItem = new ContextMenuItem(text);
item.separatorBefore = separatorBefore;
myMenu.customItems.push(item);
item.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT, mouseRelease);
function mouseRelease(event:ContextMenuEvent):void {
GlllSound.changeMusicWave();
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -