Flash uses image loading to fill mc implementation code

Source: Internet
Author: User
The code is as follows: Copy code

Fill in a mc
------------*/
Import flash. display. BitmapData;
Import flash. geom .*;
// Draw a rectangle
Function createRectangle (x: Number, y: Number, w: Number, h: Number, mc: MovieClip ){
Mc. moveTo (x, y );
Mc. lineTo (x + w, y );
Mc. lineTo (x + w, y + h );
Mc. lineTo (x, y + h );
Mc. lineTo (x, y );
Mc. endFill ();
}
// McTarget: specifies the film to be filled with MovieClip. The mcraw: specifies the strMask of the MovieClip filling material. The name of the film to be filled.
Function fillbmp MC (mcTarget: MovieClip, mcraw: MovieClip, strMask: String ){
Var rect_mc: MovieClip = mcTarget. createEmptyMovieClip ("rect_mc", mcTarget. getNextHighestDepth ());
Rect_mc.bmp = new BitmapData (20, 20, false );
Rect_mc.bmp .draw (mcraw );
Rect_mc.beginBitmapFill(rect_mc.bmp );
// You can only fill in the image drawn by the program.
CreateRectangle (0, 0, mcTarget. _ width, mcTarget. _ height, rect_mc );
// If you fill in an irregular image, you need to put a shadow film in the film you want to fill in. If you don't need to, just pass a variable without declaration.
If (strMask! = Undefined ){
Rect_mc.setMask (mcTarget [strMask]);
 }
}
// Obtain the file path
Function getFilePath (): String {
Var arrA: Array, strRen: String, strSplit: String;
StrSplit = "/";
ArrA = _ root. _ url. split (strSplit );
If (arrA. length = 1 ){
StrSplit = "\";
 }
For (var I: Number = 0; I <arrA. length-1; I ++ ){
If (I = 0 ){
StrRen = arrA [0];
} Else {
StrRen + = strSplit + "" + arrA [I];
  }
 }
StrRen + = strSplit;
Return strRen;
}

// Prompt box
Function talkYou (strA: String ){
TxtTalkYou. text = strA
}
//
Var mcImg: MovieClip = _ root. createEmptyMovieClip ("mcImg", _ root. getNextHighestDepth ());
Var mcImg2: MovieClip;
// Load the image movi1_loader listener object
Var objLoad: Object = new Object ();
ObjLoad. onLoadInit = function (target_mc: MovieClip ){
// TalkYou ("loaded, first frame ");
TalkYou ("");
// No masking
Fillbmp MC (canvas, target_mc, strMask );
// Masked
Fillbmp MC (mcMask, target_mc, "mcMask ");
// Get rid of it after it is used up: P
Target_mc.removeMovieClip ();
};
ObjLoad. onLoadComplete = function (target_mc: MovieClip, httpStatus: Number ){
TalkYou ("full download ");
};
ObjLoad. onLoadError = function (target_mc: MovieClip, errorCode: String, httpStatus: Number ){
TalkYou ("failed to load ");
};
ObjLoad. onLoadProgress = function (target_mc: MovieClip, loadedBytes: Number, totalBytes: Number ){
TalkYou ("Loading..." + Math. floor (loadedBytes/totalBytes) * 100) + "% ");
};
ObjLoad. onLoadStart = function (target_mc: MovieClip ){
TalkYou ("start Download ");
};
Var myLoader: movi1_loader = new movi1_loader ();
MyLoader. addListener (objLoad );
// Load the image path
MyLoader. loadClip (getFilePath () + "test.jpg", mcImg );

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.