As3 plain tutorial-production of as3 own loading

Source: Internet
Author: User
As3 plain tutorial --- Production of as3 own loading
I also want to learn how to write a tutorial: lol. I hope it will help you. If you find any problems, please correct them!

First, let's talk about the practices of projects (such as music videos) with content on the stage in the main scenario:
Someone asked if it was a new loader and then loader. load (this), in fact, is not so troublesome, very simple, written in the document class constructor: loaderinfo. addeventlistener (progressevent. progress, your processing function). Write the processing function as follows:
Function your processing function (E: progressevent ){
Trace (E. bytesloaded/E. bytestotal );
}
That's all. Easy!
In addition, the interface code separation project (the main stage content is generated by the:
This error is prone to errors. The common error is the same as the above MV loading. The result is that loading is 100%,
The reason is that there is usually only one frame in the main timeline of the Project separated from the interface code. Flash exports the first frame by default, and then calls the constructor of the document class, that is to say, the Progress event listening takes effect only after loading is complete. Of course, no progress is displayed!

Solution 1: double file method (for the code, see reply). This method is actually bypassed:
Create loader. As, create loader. fla, and set loader as a document class.
Create main. As, create main. fla, and set main as the document class.
In loader.
A new loader instance is loaderand loaded into main.swf with LoadRunner.
Add progress and complete listeners on loader. contentloaderinfo
Update textfield in the Progress processing function, and add loader. content to the stage in the complete processing function.
In Main.
Build stage content
Solution 2: The dual-frame method is the real solution:
But there is a small regret that the main timeline is two frames, but it is already good.
Create loader. As and the FLA file to ensure that the master axis has two frames and both are key frames.
In FLA:
Create an empty Mc and drag the MC to the second frame of the main scenario.

Double-click to edit the empty component, change the timeline of the component to two key frames, enter the second frame, and drag all components linked to the class in the library to the stage.

Cancel "export at the first frame" in the Link property of all components linked to the class:

In loader.
Create a textfield and push it to the stage. The constructor adds the SS and complete listener to loaderinfo.
Update textfield in the Progress processing function, and add enter_frame listening in the complete processing function.
Construct the stage content in the enter_frame handler and remove the enter_frame listener. That is to say, you can execute the enter_frame handler once.

[This post was last edited by Andy-Tang]

Ineffective. rar (724.61 KB)

Double File .rar (727.04 KB)

Double Frame .rar (724.95 KB)

Favorite shared score
As3 and game advanced group: 48089045 welcome to join!
Reply to reference

Subscribe to top

Andy-Tang

Intermediate Member

Post
584
Points
120
Technical score
7
Online time
432 hours
Registration Time
2007-5-7
2#

 Posted on| View the author only
Invalid code:

  1. Package {
  2. Import flash. display. movieclip;
  3. Import flash. Events .*;
  4. Import flash. Text .*;
  5. //////
  6. Public Class Loader extends movieclip {
  7. VaR TTF = new textfield (); // create a textfield instance
  8. Public Function loader (){
  9. Addchild (TTF); // push the textfield instance to the stage
  10. Loaderinfo. addeventlistener (progressevent. Progress, progresshandler); // update the text attribute of the textfield instance when the progress changes
  11. Loaderinfo. addeventlistener (event. Complete, completehandler); // The content displayed after loading is complete
  12. }
  13. Function progresshandler (E: progressevent ){
  14. TTF. Text = E. bytesloaded x 100/E. bytestotal;
  15. Trace (TTF. Text );
  16. }
  17. Function completehandler (E: Event ){
  18. Removechild (TTF); // display the text of the removal progress after loading.
  19. Addchild (New Main ());
  20. }
  21. }
  22. }

Copy code

Dual-file code-loader.

  1. Package {
  2. Import flash. display. movieclip;
  3. Import flash. display. loader;
  4. Import flash.net. URLRequest;
  5. Import flash. Text .*;
  6. Import flash. Events .*;
  7. ////
  8. Public Class Loader extends movieclip {
  9. VaR mainloader = new loader (); // create a loaderloader for loading main.swf
  10. VaR TTF = new textfield (); // create a textfield instance to display the loading percentage
  11. Public Function loader (){
  12. Addchild (TTF ); /// // textfield instance displayed on stage
  13. Mainloader. Load (New URLRequest ("main.swf"); // start with main.swf
  14. Mainloader. contentloaderinfo. addeventlistener (progressevent. Progress, progresshandler); // The update progress is displayed when the loading progress changes.
  15. Mainloader. contentloaderinfo. addeventlistener (event. Complete, completehandler); // Add main.swf to the stage after loading
  16. }
  17. Function progresshandler (E: progressevent ){
  18. TTF. Text = (E. bytesloaded x 100/E. bytestotal). tofixed (1 );
  19. }
  20. Function completehandler (E: Event ){
  21. Addchild (mainloader. content );
  22. }
  23. }
  24. }

Copy code

Dual-frame code-loader.

  1. Package {
  2. Import flash. display. movieclip;
  3. Import flash. Events .*;
  4. Import flash. Text .*;
  5. Import flash.net .*;
  6. //////
  7. Public class selfloader extends movieclip {
  8. VaR TTF = new textfield; // still create a textfield instance
  9. Public Function selfloader (){
  10. Addchild (TTF); // still pushes the textfield instance to the stage
  11. Loaderinfo. addeventlistener (progressevent. Progress, progresshandler); // update the text attribute of the textfield instance when the progress changes.
  12. Loaderinfo. addeventlistener (event. Complete, completehandler); // The content is displayed after loading is complete.
  13. }
  14. Function progresshandler (E: progressevent ){
  15. TTF. Text = E. bytesloaded * 100/E. bytestotal. tofixed ();
  16. Trace (TTF. Text );
  17. }
  18. Function completehandler (E: Event ){
  19. This. addeventlistener (event. enter_frame, enterframehandler); // Add the enter_frame listener.
  20. Trace ("loaded ");
  21. }
  22. Function enterframehandler (E: Event ){
  23. If (currentframe = 1) {/////////////////////////////////////// can be equal to 1 or 2, 1 better
  24. Stop (); //////////////////////////////////////// //// // actually stop () it can be left blank.
  25. Removechild (TTF ); //////////////////////////////////////// //// // still remove the progress display text
  26. This. removeeventlistener (event. enter_frame, enterframehandler); // you must remove the listener.
  27. Addchild (New Main );
  28. Trace ("OK ");
  29. }
  30. }
  31. }
  32. }

Copy code

[This post was last edited by Andy-Tang at, September 24 ,.]

As3 and game advanced group: 48089045 welcome to join!

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.