Flash Example: Flash internal copy paste graphic

Source: Internet
Author: User
Graphics internal copy and paste

The code is as follows:

Import Flash.display.BitmapData;
var _bmp:bitmapdata = new BitmapData (_mc._width, _mc._height);
var paste_mc:movieclip = This.createemptymovieclip ("PASTE_MC", 2);
///////////////
var _menu = new ContextMenu ();
function Copy_func () {
_bmp.draw (_MC);
Paste_menu.enabled = true;
}
function Paste_func () {
Paste_mc.attachbitmap (_bmp, 0, "always", true);
paste_mc._x = _xmouse;
paste_mc._y = _ymouse;
}
_menu.hidebuiltinitems ();
var copy_menu:contextmenuitem = new Contextmenuitem ("copy", Copy_func);
var paste_menu:contextmenuitem = new Contextmenuitem ("Paste", paste_func);
paste_menu.enabled = false;
_menu.customitems.push (Copy_menu, Paste_menu);
This.menu = _menu;

Source file Download: Click here to download source files

Copy of Camera screen

Code:

Introduction of Bitmap Class
Import Flash.display.BitmapData;
var _bmp:bitmapdata;
Turn on the camera and copy the image for the following recognition, so the video is loaded into the MC
var _cam:camera = Camera.get ();
_cam.setmode (+ +, +, true);
_mc3._video.attachvideo (_cam);
////////////////////
New Right Button menu
var _menu = new ContextMenu ();
Set a variable to record the depth of the duplicated MC, let it accumulator, don't let the MC repeat
var depth:number = 1;
copy function
function Copy_func () {
With a for loop to try, the mouse is currently located on which MC, the BMP class to draw which is like
for (var d:number = 3; d>=0; d--) {
if (_root["_MC" +d].hittest (_xmouse, _ymouse)) {
Draw the graphics of the MC that the mouse touches, and record it in the _bmp instance
_bmp = new BitmapData (_root["_MC" +d]._width, _root["_MC" +d]._height);
_bmp.draw (_root["_MC" +d));
Let the paste this right key menu take effect, it is grayed out when it is turned on
Paste_menu.enabled = true;
The mouse can not contact two MC at the same time, so once the contact is detected, it jumps out of circulation.
Break
}
}
}
Paste function
function Paste_func () {
Just paste it once, just create a new MC in the current mouse position, and then attchbitmap the new MC to create an image
_root.createemptymovieclip ("PASTE_MC" +depth, depth+100);
_root["PASTE_MC" +depth].attachbitmap (_bmp, 1, "always", true);
_root["PASTE_MC" +depth]._x = _xmouse;
_root["PASTE_MC" +depth]._y = _ymouse;
depth++;
}
This is the settings for the right key menu
_menu.hidebuiltinitems ();
var copy_menu:contextmenuitem = new Contextmenuitem ("copy", Copy_func);
var paste_menu:contextmenuitem = new Contextmenuitem ("Paste", paste_func);
paste_menu.enabled = false;
_menu.customitems.push (Copy_menu, Paste_menu);
This.menu = _menu;

Source file Download: Click here to download source files



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.