Flex mobile client masterProgramProperty splashscreenimage: You can set the preload image.
However, it only supports mxml and does not support the compilation of ActionScript.
Provides a solution to solve this problem.
Environment: Flex 4.6.0 (required. If it is 4.5, an error will be reported when the screen is rotated)
1: imagepreloader preload class
Package { Import Flash. display. Bitmap; Import Flash. display. displayobject; Import Flash. display. loader; Import Flash. display. Sprite; Import Flash. Events. event; Import Flash. Events. ioerrorevent; Import Flash. Geom. matrix; Import Flash.net. URLRequest; Import Flash. utils. gettimer; Import MX. Events. flexevent; Import MX. preloaders. ipreloaderdisplay; Import MX. preloaders. preloader; /** * <P> image preloader </P> * replace the property splashscreenimage of application, * It Can Be dynamic changed by splashimageurl and suppport ActionScript * @ Author Yaoyf * @ date 2012-07-02 * */ Public Class Imagepreloader Extends Sprite Implements Ipreloaderdisplay { Private Const Letterbox: String = "letterbox" ; Private Const Zoom: String = "zoom" ; Private Const Stretch: String = "stretch" ; Private VaR splashimage: displayobject; Private VaR splashimagewidth: number; Private VaR splashimageheight: number; Private VaR splashimageclass: class = Null ; Private VaR Loader: loader = Null ; Private VaR scalemode: String = Letterbox; Private VaR minimumdisplaytime: Number = 3000; Private VaR checkwaittime: Boolean = False ; Private VaR displaytimestart: Int =-1 ; Private VaR _ stageheight: number; Private VaR _ stagewidth: number; Private VaR splashimageurl: String = Null ; Public Function imagepreloader (){ Super ();} /** * Initialize * */ Public Function initialize (): Void {Splashimageurl = "Preloader.jpg "; // Your image URL Checkwaittime = Minimumdisplaytime> 0 ; If (Checkwaittime) If (Displaytimestart =-1 ) This . Displaytimestart = Flash. utils. gettimer (); Loader = New Loader (); loader. Load ( New URLRequest (splashimageurl); loader. contentloaderinfo. addeventlistener (event. Complete, oncomplete); loader. contentloaderinfo. addeventlistener (ioerrorevent. io_error, onioevent ); This . Stage. addeventlistener (event. Resize, stageresizehandler, False , 0, True );} Private Function stageresizehandler (Event: Event ): Void {Scalematrix ();} Protected Function onioevent (Event: ioerrorevent ): Void {Trace ("ioerror has occured:" + Event. Text );} Protected Function oncomplete (Event: Event ): Void {Dispose (); splashimage = Bitmap(event.tar get. content); addchildat (splashimage, 0 ); This . Splashimagewidth = Splashimage. width; This . Splashimageheight = Splashimage. height; scalematrix ();} /** * Scale matrix of splashimage * */ Private Function scalematrix (): Void { If (! Splashimage) Return ; Var dpiscale: Number = This . Root. scalex; var stagewidth: Number = Stage. stagewidth/ Dpiscale; var stageheight: Number = Stage. stageheight/ Dpiscale; var width: Number = Splashimagewidth; var height: Number = Splashimageheight; var M: Matrix = New Matrix (); var scalex: Number = 1 ; Var scaley: Number = 1 ; Switch (Scalemode ){ Case Zoom: scalex = Math. Max (stagewidth/width, stageheight/ Height); scaley = Scalex; Break ; Case Letterbox: scalex = Math. Min (stagewidth/width, stageheight/ Height); scaley = Scalex; Break ; Case Stretch: scalex = Stagewidth/ Width; scaley = Stageheight/ Height; Break ;} If (Scalex! = 1 | scaley! = 0 ) {Width * = Scalex; Height * =Scaley; M. Scale (scalex, scaley);} M. Translate ( -Width/2,-height/2 ); M. Translate (stagewidth /2, stageheight/2 ); Splashimage. Transform. Matrix = M ;} /** * Get current display time * */ Private Function get currentdisplaytime (): Int { If (-1 = Displaytimestart) Return -1 ; Return Flash. utils. gettimer ()- Displaytimestart ;} // Implements Public Function set preloader (OBJ: SPRITE ): Void {Obj. addeventlistener (flexevent. init_complete, preloader_initcompletehandler, False , 0,True );} Private Function preloader_initcompletehandler (Event: Event ): Void { If (Checkwaittime & currentdisplaytime < Minimumdisplaytime) This . Addeventlistener (event. enter_frame, initcompleteenterframehandler ); Else Dispatchcomplete ();} Private Function initcompleteenterframehandler (Event: Event ): Void { If (Currentdisplaytime <= minimumdisplaytime) Return ; Dispatchcomplete ();} Private Function dispatchcomplete (): Void {Dispose (); var preloader: preloader = This . Parent as preloader; preloader. removeeventlistener (flexevent. init_complete, preloader_initcompletehandler, False ); This . Removeeventlistener (event. enter_frame, initcompleteenterframehandler ); This . Stage. removeeventlistener (event. Resize, stageresizehandler, False ); Dispatchevent ( New Event (event. Complete ));} /** * Dispose resource * */ Private Function dispose (): Void { If (Splashimage ){ If ( This . Contains (splashimage )) This . Removechild (splashimage); var bit: bitmap =Splashimage as bitmap; If (Bit. bitmapdata) {bit. bitmapdata. Dispose (); bit. bitmapdata = Null ;}}} // ---------------- Implements ----------------- // Public Function get backgroundalpha (): number { Return 0 ;} Public Function set backgroundalpha (value: number ): Void {} Public Function get backgroundcolor (): uint { Return 0 ;} Public Function set backgroundcolor (value: uint ): Void {} Public Function get backgroundimage (): object { Return Null ;} Public Function set backgroundimage (value: Object ): Void {} Public Function get backgroundsize (): String { Return Null ;} Public Function set backgroundsize (value: string ): Void {} Public Function get stageheight (): number { Return _ Stageheight ;} Public Function set stageheight (value: number ): Void {_ Stageheight = Value ;} Public Function get stagewidth (): number { Return _ Stagewidth ;} Public Function set stagewidth (value: number ): Void {_ Stagewidth = Value ;}}}
2: Call method:
Main Program
<? XML version = "1.0" encoding = "UTF-8"?> <S: viewnavigatorapplication xmlns: FX = "http://ns.adobe.com/mxml/2009"Xmlns: S= "Library: // ns.adobe.com/flex/spark"Firstview= "Views. sample_flexmobilepreloaderview"Applicationdpi= "160"Preloader= "Imagepreloader"> </S: viewnavigatorapplication>