Created
July 3, 2014 07:41
-
-
Save RhinoLu/d23d80e4a281099dc12a to your computer and use it in GitHub Desktop.
AS3 Gaia Framework fake loading
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
override protected function init():void | |
{ | |
// 0ms, 表示一定會看到 Preload,至少會閃一下 | |
// 若首頁一定要看到 loading 可以這樣做 | |
// 之後要設回 150ms | |
Gaia.api.setPreloaderDelay(0); | |
initComplete(); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public var scaffold:PreloaderScaffold; | |
public function Preloader() | |
{ | |
super(); | |
scaffold.addEventListener("LOADING_COMPLETE", onScaffoldLoadingComplete); | |
} | |
private function onScaffoldLoadingComplete(e:Event):void | |
{ | |
// 假數據跑完 | |
// loading 才退場 | |
scaffold.transitionOut(); | |
transitionOutComplete(); | |
} | |
override public function transitionIn():void | |
{ | |
scaffold.transitionIn(); | |
transitionInComplete(); | |
} | |
override public function transitionOut():void | |
{ | |
// 覆寫後不用做事 | |
// 所以當 PreloadControl.as 載入完畢,loading 才不會退場 | |
} | |
override public function onProgress(event:AssetEvent):void | |
{ | |
// 傳入真實數據 | |
scaffold.real_perc = event.perc; | |
} | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public var real_perc:Number = 0; | |
private var fake_perc:Number = 0; | |
public function transitionIn():void | |
{ | |
TweenMax.to(this, .1, { autoAlpha:1 } ); | |
addEventListener(Event.ENTER_FRAME, onLoop); | |
} | |
private function onLoop(e:Event):void | |
{ | |
fake_perc += 0.01; | |
var perc:Number; | |
if (real_perc > fake_perc) { | |
perc = fake_perc; | |
}else { | |
perc = real_perc; | |
} | |
if (Math.round(perc * 100) == 100) { | |
dispatchEvent(new Event("LOADING_COMPLETE")); | |
} | |
TXT_Overall.text = "Loading " + Math.round(perc * 100) + "%"; | |
MC_Bar.scaleX = perc; | |
} | |
public function transitionOut():void | |
{ | |
TweenMax.to(this, .1, { autoAlpha:0 } ); | |
fake_perc = 0; | |
removeEventListener(Event.ENTER_FRAME, onLoop); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment