Loading external images and controlling image loading

Source: Internet
Author: User
Loading external images and controlling image loading

Many friends are asking how to load external files, such as load jpg, load swf, and load sound.
How can I control the load when it comes in? How to determine the loading? This tutorial is about loading external resources.

In this tutorial, you can learn a little bit about the image (jpg). I believe you will

Some gains.

First, let's take a look at the results of this example.
Http://tuliping.topcities.com/loadimage.html

Let's take a look at the Code and its analysis:

Stage. showMenu = false; // right-click the screen to block it.
Stage. scaleMode = "noBorder"; // no menu for the player
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 images
Mc. loadMovie ("test.jpg ");
// Load an image named test (in jpg format)
Mc. _ visible = false;
// Note that 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 of a dynamic text box
LoadBar. _ width = fig * 100;
// The length of the progress bar, whose instance name: loadBar in the home scene
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.
//-------------------------------------------------------------------------------
MovieClip. prototype. jump = function (scale, frequency, quotiety ){
// Three parameters: scale-image ratio frequency-elasticity 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.
Mc. onEnterFrame = function (){
If (this. hitTest (_ root. _ xmouse, _ root. _ ymouse, true )){
This. jump (70,. 9,. 6 );
} Else {
This. jumpl (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: loadTest

Postscript: After loading, you can use it for Customs operations.

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.