As to create the copy paste and other functional class _flash as

Source: Internet
Author: User
Main code:
Copy Code code as follows:


Define public functions ...
Class ClipBoard extends Object {
static Var $contents: Object;
static Var $operation: String;
function ClipBoard () {
}
Define the effect when cutting is selected ...
public static function cut (obj) {
Obj._alpha = 50;
$contents = obj;
$operation = "Cut";
}
Define copy Function ...
public static function copy (obj) {
$contents = obj;
$operation = "Copy";
}
Define Delete Function ...
public static function remove (obj) {
$contents = obj;
$operation = "Remove";
$contents. Removemovieclip ();
}
Define clockwise rotation ...
public static function rotation (obj) {
$contents = obj;
$operation = "Rotation";
$contents. _rotation + 45;
}
Define counterclockwise rotation ...
public static function Rotation2 (obj) {
$contents = obj;
$operation = "Rotation2";
$contents. _rotation-= 45;
}
Define move ...
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;
}
};
}
}
Definition Refresh ...
public static function Refish () {
GetURL ("Javascript:location.reload ()");
}
Define Paste Function ...
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 "Cut __x":
Cut (obj);
Break
Case "Copy __c":
Copy (obj);
Break
Case "Paste __p":
Paste ();
Break
Case "Delete __d":
Remove (obj);
Break
Case "Refresh _f5":
Refish ();
Break
Case "rotate to right":
Rotation (obj);
Break
Case "Rotate Left":
Rotation2 (obj);
Break
Case "Move this ball":
Movethis (obj);
Break
}
}
}

Define right-click menu:

QUOTE:
Copy Code code as follows:

_global. $clipboard = new clipboard ();
function Menucallback (obj, menuobj) {
var Empty:boolean = _global. $clipboard. IsEmpty ();
Menuobj.customitems = [];
If the object is a movie clip, not a _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 ("Cut __x", _global. $clipboard. Handlemenucommand);
var copyitem = new Contextmenuitem ("Copy __c", _global. $clipboard. Handlemenucommand);
var pasteitem = new Contextmenuitem ("Paste __p", _global. $clipboard. Handlemenucommand);
var remove = new Contextmenuitem ("Delete __d", _global. $clipboard. Handlemenucommand);
var refish = new Contextmenuitem ("Refresh _f5", _global. $clipboard. Handlemenucommand);
var rotation = new Contextmenuitem ("Rotate to right", _global. $clipboard. Handlemenucommand);
var rotation2 = new Contextmenuitem ("Rotate to left", _global. $clipboard. Handlemenucommand);
var movethis = new Contextmenuitem ("Move this Ball", _global. $clipboard. Handlemenucommand);
MovieClip.prototype.menu = MyMenu;
This.menu = MyMenu;
Stop ();

The use of the method is very simple, directly to the production of the MC into the scene, and then add the following code in the MC:

Copy Code code as follows:


On (release) {
Stopdrag ();
End Behavior
}
On (Press) {
StartDrag (this);
End Behavior
Mx.behaviors.DepthControl.bringToFront (this);
End Behavior
}
Note the download of the "Clipboard.as" class file, to be placed in the SWF peer directory ...
Package download

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.