Loading this thing, to put it bluntly is actually gives the user feedback one kind of manifestation, in the client's loading, usually takes the mouse the hand type change to express, but in the web side, the loading creativity is endless, moreover gives the user the feedback to be better. This article will mainly explain some problems in the production of loading in Flash.
First look at the principle of loading. In Flash, the purpose of making loading is to preload a portion of the content (you can choose to load it all, or after loading it), and then display the main contents of the Flash. Generally speaking, loading is placed on the top of the first frame (also can not be placed in the first frame, such as in any frame, but in the first frame you have to make a jump, so that the play head to the loading frame). Notice here a problem, if your flash program has from the component library to export components (default is the first frame export), to export the original all loaded before the first frame will display the content (that is, your loading). So it's possible that the first frame you exported is too large to occupy a large part of the entire flash application, such as 50%, then we actually run the effect is in a blank after the loading from 50% start to show.
To avoid the above problem (an obvious bad user experience), I usually use two methods:
First, cancel the export of the components to be exported, focus them on a frame (except the one that you do loading), and then start running your program after the frame of the component.
Second, use another SWF to load the SWF that needs to be done loading. This method can have a relatively complete load progress bar as well as percent text, the disadvantage is easy to cause other problems, this will be discussed later.
For example, I want to do a loading for a.swf, the key code is as follows:
......
This. Loaderinfo. AddEventListener (spanrogressevent. spanrogress,loadspanrogress);
This. Loaderinfo. AddEventListener (Event. Comspanlete,loadcomspanlete);
......
A new Loaderinfo class is added to the AS3.0 to provide information about the loaded SWF and image files. Flashplayer to monitor the load content feedback by dispatching the Loadprogress method of Progressevent object, when the load is complete, Flashplayer then dispatch the Loadcomple method of the event object. The Loadprogress method is a method that I define to listen for loading progress, and all information about loading can be fed back in this method:
......
Spanrivate functionloadspanrogress (e:spanrogressevent)
{
var loaded:uint= e. bytesloaded;
Vartotal:uint= E. bytestotal;
varspanercent:number= Int ((loaded/total) * 100);
Trace (spanercent+ "%");
}
......
The above code output is loading the percentage of content, this is the simplest kind of feedback, but you can enrich the content of your loading in this code to make it more interesting so that the user can be aware of the download progress while waiting for the download, or watch a beautiful animation at this time It all depends on your design. Now that the load is complete, you can execute the LoadComplete method. Add the action you want to the LoadComplete method, such as giving the user a play button so that the user can choose it, or go directly to a frame to play.
As I said earlier, adding loading directly to the SWF may cause loading not to start at 1%, and then you can load another SWF with one SWF to implement the complete loading, for example, I want to load a.swf in b.swf, then use loader to load a.swf in b.swf programs. It should be noted that the monitoring of loader loading progress requires the use of loader contentloaderinfo properties, not loaderinfo. The relationship between Loaderinfo and Contentloaderinfo is shown in the following illustration:
Because b.swf only play the role of loading a.swf, and there is no other display content, so its own load can be ignored, this method can be more complete display a.swf loading process. However, the use of this method also raises a number of problems, such as you in the a.swf with the web side of the communication, using the loaderinfo of the parameters attribute, you are loading a.swf with b.swf, the communication will fail. This is because the Flashvars HTML parameter only affects the main SWF (in the case of b.swf), which means that you can complete the communication in b.swf, but a.swf not. So, we can get the message to the page in b.swf first, then let a.swf get this information from b.swf. As I normally do, if the B.swf document class is main.as, then define a static property in main.as such as Prama (public static Var Prama), to hold the transmitted information. Then get this information through the Main.prama in the a.swf. This indirectly realizes the communication between the a.swf and the web side.
To sum up, this article is not to introduce how to make a complete loading, I believe that the example of loading is not uncommon on the internet, but only understand the basic principles of loading production, can fundamentally make more normative and friendly loading.