ASで作ったコピー貼り付けなどの機能類
主なコード:
// 。。。
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;
}
}
}
は、右キーメニューを定義します。QUOTE:
_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に下記のコードを追加します。ダウンロード