; var newname = $contents._name+newdepth; $contents.removeMovieClip(""); } else { return; } } public function isEmpty():Boolean { if ($contents != undefined) { return false; } else { return true; } } public function handleMenuCommand(obj, item):Void { switch (item.caption) { case "剪切__X" : cut(obj); break; case "复制__C" : copy(obj); break; case "粘贴__P" : paste(); break; case "删除__D" : remove(obj); break; case "刷新_F5" : refish(); break; case "往右旋转" : rotation(obj); break; case "往左旋转" : rotation2(obj); break; case "移动此球" : movethis(obj); break; } } }
定义右键菜单:
_global.$clipboard = new ClipBoard(); function menuCallback(obj, menuObj) { var empty:Boolean = _global.$clipboard.isEmpty(); menuObj.customItems = []; // 如果对象为影片剪辑,而不是 _root if ((obj instanceof MovieClip) && (obj != _level0)) { menuObj.customItems.push(cutItem); menuObj.customItems.push(copyItem); menuObj.customItems.push(remove); menuObj.customItems.push(refish); menuObj.customItems.push(rotation); menuObj.customItems.push(rotation2); menuObj.customItems.push(movethis); if (!empty) { menuObj.customItems.push(pasteItem); menuObj.customItems.push(refish); } } else if (obj == _level0 && !empty) { menuObj.customItems.push(pasteItem); menuObj.customItems.push(refish); } } var myMenu = new ContextMenu(menuCallback); myMenu.hideBuiltInItems(); var cutItem = new ContextMenuItem("剪切__X", _global.$clipboard.handleMenuCommand); var copyItem = new ContextMenuItem("复制__C", _global.$clipboard.handleMenuCommand); var pasteItem = new ContextMenuItem("粘贴__P", _global.$clipboard.handleMenuCommand); var remove = new ContextMenuItem("删除__D", _global.$clipboard.handleMenuCommand); var refish = new ContextMenuItem("刷新_F5", _global.$clipboard.handleMenuCommand); var rotation = new ContextMenuItem("往右旋转", _global.$clipboard.handleMenuCommand); var rotation2 = new ContextMenuItem("往左旋转", _global.$clipboard.handleMenuCommand); var movethis = new ContextMenuItem("移动此球", _global.$clipboard.handleMenuCommand); MovieClip.prototype.menu = myMenu; this.menu = myMenu; stop();
|