浏览 5015 次
锁定老帖子 主题:Flex Preloader
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
|
|
---|---|
作者 | 正文 |
发表时间:2008-09-04
最近也用到这个preloader,把它改造了一下,加载完flash后在显示组件, package com.preload { import flash.display.Loader; import flash.events.Event; import flash.events.TimerEvent; import flash.geom.Point; import flash.utils.ByteArray; import flash.utils.Timer; public class WelcomeScreen extends Loader { [Embed(source="../asserts/welcome.swf", mimeType="application/octet-stream")] public var WelcomeScreenGraphic : Class; public var timer : Timer; private var fadeInRate : Number = .01; private var fadeOutRate : Number = .02; private var timeAutoClose : int = 100; public var ready : Boolean = false; public var COMPLETE_EVENT : String = "complete"; private var completeFlag : Boolean = true; public function WelcomeScreen() { this.visible = false; this.alpha = 0; timer = new Timer(1); timer.addEventListener(TimerEvent.TIMER, updateView); timer.start(); this.loadBytes(new WelcomeScreenGraphic() as ByteArray); //this.addEventListener( MouseEvent.MOUSE_DOWN, mouseDown ); } public function updateView(event : TimerEvent):void { if(completeFlag) { if(this.alpha < 1) this.alpha = this.alpha + this.fadeInRate; this.stage.addChild(this); var point : Point = new Point(); this.x = this.stage.stageWidth/2 - this.width/2; this.y = this.stage.stageHeight/2 - this.height/2; this.visible=true; completeFlag = false; } if (this.ready && timer.currentCount > this.timeAutoClose) closeScreen(); } public function closeScreen():void { timer.removeEventListener(TimerEvent.TIMER, updateView); timer.addEventListener(TimerEvent.TIMER, closeScreenFade); } public function closeScreenFade(event : TimerEvent):void { timer.stop(); this.parent.removeChild(this); dispatchEvent(new Event(COMPLETE_EVENT)); } } } package com.preload { import flash.display.Sprite; import flash.events.Event; import flash.events.ProgressEvent; import mx.events.*; import mx.preloaders.DownloadProgressBar; public class CustomPreloader extends DownloadProgressBar { public var wcs:WelcomeScreen; public function CustomPreloader() { super(); wcs = new WelcomeScreen(); this.addChild(wcs) } override public function set preloader( preloader:Sprite ):void { preloader.addEventListener(ProgressEvent.PROGRESS, SWFDownloadProgress); preloader.addEventListener(Event.COMPLETE, SWFDownloadComplete); preloader.addEventListener(FlexEvent.INIT_PROGRESS, FlexInitProgress); preloader.addEventListener(FlexEvent.INIT_COMPLETE, FlexInitComplete); this.wcs.addEventListener(wcs.COMPLETE_EVENT, wcsComplete); } private function SWFDownloadProgress(event : ProgressEvent):void {} private function SWFDownloadComplete(event : Event):void {} private function FlexInitProgress(event : Event):void {} private function FlexInitComplete(event : Event):void { wcs.ready = true; } private function wcsComplete(event : Event) : void { wcs.ready = true; dispatchEvent(new Event( Event.COMPLETE)); } } } flash动画就不上传了.望大家参考. 声明:ITeye文章版权属于作者,受法律保护。没有作者书面许可不得转载。
推荐链接
|
|
返回顶楼 | |