Custom flex loading Interface

Source: Internet
Author: User

First ~ The principle of custom flex loading is to inherit the MX. preloaders. downloadprogressbar class, and then rewrite the related methods ..

Code

  Package  
{
Import Flash. display. * ;
Import Flash. Events. * ;
Import Flash.net. * ;
Import Flash. Text. textfield;
Import Flash. Text. textformat;
Import MX. Events. flexevent;
Import MX. preloaders. downloadprogressbar;
Public Class Loadingexampleprogressbar Extends Downloadprogressbar
{
Private VaR logo: loader;
Private VaR TXT: textfield;
Private VaR _ preloader: SPRITE;
Public Function loadingexampleprogressbar ()
{
Logo = New Loader ();
Logo. Load ( New URLRequest ( " L4cd.png " ));
Addchild (logo );
VaR style: textformat = New Textformat ( Null , Null , 0 xffffff , Null , Null , Null , Null , Null , " Center " );
Txt = New Textfield ();
TXT. defaulttextformat = Style;
TXT. Width = 200 ;
TXT. selectable = False ;
TXT. Height = 20 ;
Addchild (txt );
Super ();
}
// The most importantCodeHere we will rewrite the preloader so that the SWF can load the file ~ Perform the operations you want ~
Override Public Function set preloader (value: SPRITE ): Void
{
_ Preloader = Value
// Four listeners ~ Loading progress, loading completion, initialization progress, and initialization completion
_ Preloader. addeventlistener (progressevent. Progress, load_progress );
_ Preloader. addeventlistener (event. Complete, load_complete );
_ Preloader. addeventlistener (flexevent. init_progress, init_progress );
_ Preloader. addeventlistener (flexevent. init_complete, init_complete );
Stage. addeventlistener (event. Resize, resize)
Resize ( Null );
}
Private Function remove (): Void {
_ Preloader. removeeventlistener (progressevent. Progress, load_progress );
_ Preloader. removeeventlistener (event. Complete, load_complete );
_ Preloader. removeeventlistener (flexevent. init_progress, init_progress );
_ Preloader. removeeventlistener (flexevent. init_complete, init_complete );
Stage. removeeventlistener (event. Resize, resize)
}
Private Function resize (E: Event ): Void {
Logo. x = (Stage. stagewidth - 40 ) / 2 ;
Logo. Y = (Stage. stageheight - 80 ) / 2 ;
TXT. x = (Stage. stagewidth - 200 ) / 2 ;
TXT. Y = Logo. Y + 40 + 5 ;
Graphics. Clear ();
Graphics. beginfill ( Zero X 333333 );
Graphics. drawrect ( 0 , 0 , Stage. stagewidth, stage. stageheight );
Graphics. endfill ();
}
Private Function load_progress (E: progressevent ): Void {
TXT. Text = " Loading... " + Int (E. bytesloaded / E. bytestotal * 100 ) + " % " ;
}
Private Function load_complete (E: Event ): Void {
TXT. Text = " Loaded! "
}
Private Function init_progress (E: flexevent ): Void {
TXT. Text = " Initializing... "
}
Private Function init_complete (E: flexevent ): Void {
TXT. Text = " Initialization is complete! "
Remove ()
// At last, a DPE event. Complete Event is required. This indicates that the SWF will continue to operate after loading ~
Dispatchevent ( New Event (event. Complete ))
}
}
} & Nbsp;

 

After customizing the loading class... let's test a new app ..

Code

  <?  XML version = "1.0" encoding = "UTF-8"  ?>  
< MX: Application Xmlns: MX = "Http://www.adobe.com/2006/mxml" Layout = "Absolute"
Preloader = "Loadingexampleprogressbar"
Backgroundgradientalphas = "[1.0, 1.0]" Backgroundgradientcolors = "[#333333, #333333]"
</MX: Application >

 

    1. No need to write any code ..
      You only need
      Set preloader to the class you just defined under the label (I am calling loadingexampleprogressbar)
      Save and you will see the effect ~



The aboveArticleIt is reprinted, but it is actually very simple. Flash is built. Here we only need to know which base class is inherited by the flex loading class, but it is still very simple. Transfer today
Here, I hope other friends can learn from me.

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.