Flex 4 ~ set preloader swf

這是張某弄的= =+


default application MXML

<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600" creationComplete="init()"
preloader="comp.GgyyPreloader" backgroundColor="#f7babd" >


file
src/comp/GgyyPreloader.as


content
--------------------------------------------------------------------------------------------------

package comp
{
import flash.display.Loader;
import flash.display.MovieClip;
import flash.display.Sprite;
import flash.events.Event;
import flash.events.ProgressEvent;
import flash.utils.ByteArray;

import mx.controls.Label;
import mx.controls.SWFLoader;
import mx.core.FlexGlobals;
import mx.events.FlexEvent;
import mx.preloaders.DownloadProgressBar;

public class GgyyPreloader extends DownloadProgressBar
{

[Embed(source="swf/loading3.swf", mimeType="application/octet-stream")]
public var WelcomeScreenGraphic:Class;

private const bgColor:uint = 0xf7babd;

private var _preloader:Sprite;

public function GgyyPreloader():void
{
super();

this.backgroundColor = 0xf7babd;
this.alpha = 1;

var loader:Loader= new Loader();
loader.loadBytes( new WelcomeScreenGraphic() as ByteArray );
this.addChild(loader);

}

public override function set preloader(preloader:Sprite):void
{
preloader.visible = false;
_preloader = preloader;

preloader.addEventListener(ProgressEvent.PROGRESS, onSWFDownloadProgress);
preloader.addEventListener(Event.COMPLETE, onSWFDownloadComplete);
preloader.addEventListener(FlexEvent.INIT_PROGRESS, onFlexInitProgress);
preloader.addEventListener(FlexEvent.INIT_COMPLETE, onFlexInitComplete);
}

private function centerPreloader():void
{
if ((stage.stageWidth > 0) && (_preloader)) {
x = (stage.stageWidth / 2) - (1024 / 2);
y = (stage.stageHeight / 2) - (700 / 2);
_preloader.visible = true;
}
}

private function onSWFDownloadProgress(event:ProgressEvent):void
{
centerPreloader();

}

private function onSWFDownloadComplete(event:Event):void
{

}

private function onFlexInitProgress(event:FlexEvent):void
{

}

private function onFlexInitComplete(event:FlexEvent):void
{

dispatchEvent( new Event(Event.COMPLETE));
}
}
}

沒有留言: