Loading external images and controlling image loading

Source: Internet
Author: User

Let's take a look at the code and its analysis ::
Stage. showMenu = false; // right-click the screen to block the Stage. scaleMode = "noBorder"; // The player has no menu Stage. scaleMode = "noScale"; // disable scaling // The above code is just a personal hobby. This. createEmptyMovieClip ("preloader", 10000); this. createEmptyMovieClip ("mc", 10001); // dynamically create a mc to load the image mc. loadMovie ("test.jpg"); // load an image named test (in jpg format) mc. _ visible = false; // The shader mc is invisible/* ------------------------------------------------ preloader. onEnterFrame = function () {var l = mc. getBytesLoaded (); var t = mc. getBytesTotal (); var getPercent = l/t; loadText = Math. round (getPercent * 100) + "% completed"; // var: loadTest loadBar in a dynamic text box. _ width = getPercent * 100; // The length of the progress bar. In the home scene, its instance name: loadBar if (l> 0 & l> = t) {mc. _ visible = 1; delete this. onEnterFrame; // make mc visible after loading, and stop loop (delete this. onEnterFrame;)} */---------------------- This code is used to determine the loading status. // compile MovieClip. prototype. jump = function (scale, frequency, quotiety) {// three parameters: scale -- image ratio frequency --- elastic frequency quotiety --- elasticity coefficient this. tempo + = (scale-this. _ xscale) * frequency; this. tempo * = quotiety; this. _ xscale = this. _ yscale + = this. tempo; // place the image in the middle of the scene (550X400) this. -x = 275-(this. _ width/2); this. _ y = 200-(this. _ height/2 );
}; // -------- Set the image's elastic effect. You can use this effect in other aspects, such as buttons.
// ----------- Determines the mouse event. When the mouse and image collide, the user-defined function is called and assigned a value to mc. onEnterFrame = function () {if (this. hitTest (_ root. _ xmouse, _ root. _ ymouse, true) {this. jump (70 ,. 9 ,. 6);} else {this. jump (30 ,. 6 ,. 5 );}}};
The above code is in the first frame of the main scenario.
Manually create MC, draw a line, and use it as a progress bar to pull MC from the library to the main scenario, instance name: loadBar. Create a dynamic text box in the home scene to display the loading percentage. var: loadText
Postscript:After loading, you can use the function.
So pay attention to the judgment of loading. This is especially important when loading external 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.