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
}
}
}