|
|
实例三、Customizing Context Menu
一、涉及特性
这个实例反映了Flash MX 2004在编程方面的重大改进。其中包括了as文件的应用,系统的_global.$clipboard变量的使用,ContextMenu(menufun) 函数的调用,ContextMenuItem()函数的调用,已经MovieClip.prototype.menu变量的使用。通过这几个函数和变量的操作,就可以轻松地操作Flash Player中的菜单了。
二、制作过程
1、新建一个Action Script File,命名为“ClipBoard.as”,内容如下:
/* Copyright 2003 Macromedia, Inc. All rights reserved.
The following is Sample Code and is subject to all restrictions
on such code as contained in the End User License Agreement
accompanying this product.
*/
class ClipBoard extends Object{ //注释1
static var $contents:Object; //注释2
static var $operation:String; //注释3
function ClipBoard() {} //注释4
static public function cut(obj) { //注释5
obj._alpha = 50; //注释6
$contents = obj; //注释7
$operation = "cut"; //注释8
}
static public function copy(obj) { //注释9
$contents = obj;
$operation = "copy";
}
static public function paste() { //注释10
if ($operation == "cut") { //注释11
$contents._x = _root._xmouse; //注释12
$contents._y = _root._ymouse;
$contents._alpha = 100; //注释13
$contents = undefined; //注释14
$operation = ""; //注释15
} else if ($operation == "copy") { //注释16
var newdepth = $contents._parent.getNextHighestDepth(); //注释17
var newname = $contents._name + newdepth; //注释18
$contents.duplicateMovieClip(newname, newdepth); //注释19
$contents._parent[newname]._x = _root._xmouse; //注释20
$contents._parent[newname]._y = _root._ymouse;
$contents._alpha = 100;
$contents._parent[newname]._alpha = 100;
} else {
return; //注释21
}
}
public function isEmpty():Boolean { //注释22
if ($contents != undefined) { //注释23
return false;
} else {
return true;
}
}
public function handleMenuCommand(obj, item):Void { //注释24
switch (item.caption) { //注释25
case "Cut object": //注释26
cut(obj);
break;
case "Copy object": //注释27
copy(obj);
break;
case "Paste object": //注释28
paste();
break;
}
}
}
|
|
|
焦点文章
| | |
|
|
|