How to Write loading in as3 document class

Source: Internet
Author: User

Loading requires at least two frames. This is a point to note. Anyone who understands the loading principle should know about it.
The first frame is the loading animation.
The second frame is your content.
The followingCodeAssume that flash has two frames:
The first frame is automatically stopped at the beginning, and then the loading operation is performed. to display the progress, you can write the operation you need in loadprogress. After loading, you can jump to the second frame and stop it. Note that in the main function, addframescript is used to add the stop () code to the second frame of the animation. Here it is not necessary. addframescript is a hidden function, here is just a test (PS: In addframescript, the first is the number of frames, followed by the function to be loaded, and the number of frames starts from 0 ).

 

Code

Package {
Import flash. display. * ;
Import flash. Events. * ;
Public class main extends movieclip {
Public Function Main (): Void {
Stop ()

// You can also use addframescript to add code to the specified frame.
// Addframescript (1, framescript)

// Call the load script
Loadscript ()
}
Private Function Loadscript (): Void {
// In as3, so all display objects can use loaderinfo to listen on the loading status.
// We add a "" progress "" and a "complete ""
Root. loaderinfo. addeventlistener (progressevent. Progress, loadprogress, False , 0 , True )
Root. loaderinfo. addeventlistener (event. Complete, init, False , 0 , True )
}
Private Function Loadprogress (E: progressevent ): Void {
// This function is called during the loading process.
// E. bytesloaded/E. bytestotal are loaded bytes and Total Bytes respectively.
// You can view the progress here.
Trace (E. bytesloaded, E. bytestotal)
}
Private Function Init (E: Event ): Void {
// After loading is completed, we will jump to the second frame for playing.
Gotoandstop ( 2 )
// Operation code ....
}
Private Function Framescript (): Void {
Trace ( "" Second frame stopped "" )
Stop ()
// Operation
}
}
}

 

 

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.