?? glllmenu.as
字號(hào):
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. -
* 自定義右鍵菜單類實(shí)現(xiàn)IMenu
*
* @author <a href="http://www.LL19.com/">LL19.com</a>
*
*/
public class GlllMenu implements IMenu {
public var myMenu:ContextMenu;
private var defaultItems:ContextMenuBuiltInItems;
/**
* 構(gòu)建菜單
* @param showMenu no屏蔽右鍵所有菜單,或者選擇顯示例如 print,zoom 則顯示打印和放大縮小(用,隔開),只顯示其中之一直接輸入字符,有效字符包括“print,forwardAndBack,zoom,save,rewind,quality,play,loop” 若不構(gòu)建傳入"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") :
//顯示前進(jìn)后退
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("傳入?yún)?shù)showMenu: " + menuList[i] + " 沒有執(zhí)行");
}
}
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") :
//顯示前進(jìn)后退
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("傳入?yún)?shù)showMenu: " + showMenu + " 沒有執(zhí)行");
}
myObject.contextMenu = myMenu;
}
else {}
}
catch (e:Error) {
trace("構(gòu)建菜單錯(cuò)誤 myMc有否傳入正確?");
trace(e.message);
throw e;
}
finally {
}
}
else {
myObject.contextMenu = myMenu;
}
}
/**
* 用來建立右鍵鏈接菜單
* @param title 鏈接的標(biāo)題
* @param url 鏈接的地址
* @param separatorBefore 菜單項(xiàng)上方是否顯示分隔條
*/
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 菜單項(xiàng)上方是否顯示分隔條
*/
public function buildTextMenu(text:String,ISeparatorBefore:Boolean):void {
var item:ContextMenuItem = new ContextMenuItem(text);
item.separatorBefore = ISeparatorBefore;
myMenu.customItems.push(item);
}
/**
* 用來播放當(dāng)前音樂
* @param text 鏈接的文字
* @param separatorBefore 菜單項(xiàng)上方是否顯示分隔條
*/
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();
}
}
/**
* 用來停止播放當(dāng)前音樂
* @param text 顯示文字
* @param separatorBefore 菜單項(xiàng)上方是否顯示分隔條
*/
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 菜單項(xiàng)上方是否顯示分隔條
*/
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 菜單項(xiàng)上方是否顯示分隔條
*/
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();
}
}
/**
* 用來關(guān)閉聲音
* @param text 顯示文字
* @param separatorBefore 菜單項(xiàng)上方是否顯示分隔條
*/
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 菜單項(xiàng)上方是否顯示分隔條
*/
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 菜單項(xiàng)上方是否顯示分隔條
*/
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();
}
}
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -