演示
源碼下載:flash_copy.rar
主要代碼:
//定義公共函數(shù)。。。 class ClipBoard extends Object { static var $contents:Object; static var $operation:String; function ClipBoard() { } //定義當(dāng)選擇剪切時(shí)的效果。。。 public static function cut(obj) { obj._alpha = 50; $contents = obj; $operation = "cut"; } //定義復(fù)制函數(shù)。。。 public static function copy(obj) { $contents = obj; $operation = "copy"; } //定義刪除函數(shù)。。。 public static function remove(obj) { $contents = obj; $operation = "remove"; $contents.removeMovieClip(); } //定義順時(shí)針旋轉(zhuǎn)。。。 public static function rotation(obj) { $contents = obj; $operation = "rotation"; $contents._rotation += 45; } //定義逆時(shí)針旋轉(zhuǎn)。。。 public static function rotation2(obj) { $contents = obj; $operation = "rotation2"; $contents._rotation -= 45; } //定義移動(dòng)。。。 private static var xm:Number; private static var ym:Number; public static function movethis(obj) { $contents = obj; $operation = "movethis"; _root.onMouseDown = function() { xm = _xmouse; ym = _ymouse; movethisit(); }; function movethisit() { _root.onEnterFrame = function() { $contents._x += (xm-$contents._x)/5; $contents._y += (ym-$contents._y)/5; if (Math.abs($contents._x-xm)<0.5) { _root.onEnterFrame = undefined; } }; } } //定義刷新。。。 public static function refish() { getURL("javascript:location.reload()"); } //定義粘貼功能。。。 public static function paste() { if ($operation == "cut") { $contents._x = _root._xmouse; $contents._y = _root._ymouse; $contents._alpha = 100; $contents = undefined; $operation = ""; } else if ($operation == "copy") { var newdepth = $contents._parent.getNextHighestDepth(); var newname = $contents._name+newdepth; $contents.duplicateMovieClip(newname, newdepth); $contents._parent[newname]._x = _root._xmouse; $contents._parent[newname]._y = _root._ymouse; $contents._alpha = 100; $contents._parent[newname]._alpha = 100; } else if ($operation == "remove") { var newdepth = $contents._parent.getNextHighestDepth(); 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 "復(fù)制__C" : copy(obj); break; case "粘貼__P" : paste(); break; case "刪除__D" : remove(obj); break; case "刷新_F5" : refish(); break; case "往右旋轉(zhuǎn)" : rotation(obj); break; case "往左旋轉(zhuǎn)" : rotation2(obj); break; case "移動(dòng)此球" : 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("復(fù)制__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("往右旋轉(zhuǎn)", _global.$clipboard.handleMenuCommand); var rotation2 = new ContextMenuItem("往左旋轉(zhuǎn)", _global.$clipboard.handleMenuCommand); var movethis = new ContextMenuItem("移動(dòng)此球", _global.$clipboard.handleMenuCommand); MovieClip.prototype.menu = myMenu; this.menu = myMenu; stop();
使用方法很簡單,直接將制作好的MC拖入場景,然后在MC中加入如下代碼:
on (release) { stopDrag(); //結(jié)束行為 } on (press) { startDrag(this); //結(jié)束行為 mx.behaviors.DepthControl.bringToFront(this); //結(jié)束行為 }
注意下載的“ClipBoard.as”類文件,要放在SWF同級(jí)目錄下。。。
經(jīng)典論壇交流: http://bbs.blueidea.com/thread-2835562-1-1.html
本文鏈接:http://www.95time.cn/download/product/2008/5459.asp
出處:藍(lán)色理想
責(zé)任編輯:bluehearts
|