欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

Flash AS教程:复制粘贴类

程序员文章站 2023-03-30 20:26:45
源码下载:flash_copy.rar 主要代码: //定义公共函数。。。 class ClipBoard extends Object { static var $contents:Object; static var $operation:String; function Cl... 08-10-06...
源码下载:flash_copy.rar
主要代码

//定义公共函数。。。
class clipboard extends object {
static var $contents:object;
static var $operation:string;
function clipboard() {
}
//定义当选择剪切时的效果。。。
public static function cut(obj) {
obj._alpha = 50;
$contents = obj;
$operation = "cut";
}
//定义复制函数。。。
public static function copy(obj) {
$contents = obj;
$operation = "copy";
}
//定义删除函数。。。
public static function remove(obj) {
$contents = obj;
$operation = "remove";
$contents.removemovieclip();
}
//定义顺时针旋转。。。
public static function rotation(obj) {
$contents = obj;
$operation = "rotation";
$contents._rotation = 45;
}
//定义逆时针旋转。。。
public static function rotation2(obj) {
$contents = obj;
$operation = "rotation2";
$contents._rotation -= 45;
}
//定义移动。。。
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 "复制__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();
使用方法很简单,直接将制作好的mc拖入场景,然后在mc中加入如下代码:
on (release) {
stopdrag();
//结束行为
}
on (press) {
startdrag(this);
//结束行为
mx.behaviors.depthcontrol.bringtofront(this);
//结束行为
}
注意下载的“clipboard.as”类文件,要放在swf同级目录下。。。