AS copy and paste

Source: Internet
Author: User

For the AS copy and paste function, FLASH uses AS to create copy and paste function classes. Let's take a look at the call method.

On (release ){
StopDrag ();
// End the action
}
On (press ){
StartDrag (this );
// End the action
Mx. behaviors. DepthControl. bringToFront (this );
// End the action
}
Effect animation

Right-click menu:

_ Global. $ clipboard = new ClipBoard ();
Function menuCallback (obj, menuObj ){
Var empty: Boolean = _ global. $ clipboard. isEmpty ();
MenuObj. customItems = [];
// If the object is a video clip, instead of _ 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 the right", _ global. $ clipboard. handleMenuCommand );
Var rotation2 = new ContextMenuItem ("rotate to the left", _ global. $ clipboard. handleMenuCommand );
Var movethis = new ContextMenuItem ("move this ball", _ global. $ clipboard. handleMenuCommand );
MovieClip. prototype. menu = myMenu;
This. menu = myMenu;
Stop ();

// Define public functions...
Class ClipBoard extends Object {
Static var $ contents: Object;
Static var $ operation: String;
Function ClipBoard (){
}
// Define the effect when selecting cut...
Public static function cut (obj ){
Obj. _ alpha = 50;
$ Contents = obj;
$ Operation = "cut ";
}
// Define the replication function...
Public static function copy (obj ){
$ Contents = obj;
$ Operation = "copy ";
}
// Define the 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 a counter-clockwise rotation...
Public static function rotation2 (obj ){
$ Contents = obj;
$ Operation = "rotation2 ";
$ Contents. _ rotation-= 45;
}
// Define movement...
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;
}
};
}
}
// Refresh definition...
Public static function refish (){
GetURL ("javascript: location. reload ()");
}
// Define the 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 the right ":
Rotation (obj );
Break;
Case "rotate left ":
Rotation2 (obj );
Break;
Case "move the ball ":
Movethis (obj );
Break;
}
}
}

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.