想起当年学flash的时候,最先学的就是做loading ,哈哈,成天做loading,那几行代码和那几个步骤全都背下来了。
自从来到了高级的Flex时代,loading全都自动生成了真是方便,但天天看Flex的Loading画面难免会有点审美疲劳 ,
所以花了点时间研究了一下怎么自己画Flex的loading画面。
点此演示
时间关系,我只简单的画了一下, 这里是fla ,其实你想怎么画都可以
主要代码:
自定义的Preloader:
package
{
import flash.display.MovieClip;
import flash.display.Sprite;
import flash.events.Event;
import flash.events.ProgressEvent;
import mx.events.FlexEvent;
import mx.preloaders.IPreloaderDisplay;
import mx.preloaders.Preloader;
public class nPreloader extends Sprite implements IPreloaderDisplay
{
[Embed(source="mc.swf", symbol="loader_mc")]
private var LoaderMC:Class;
private var _loader_mc:MovieClip
private var _preloader:Preloader;
public function nPreloader()
{
super();
this._loader_mc = new LoaderMC()
this.addChild(this._loader_mc);
this._loader_mc.gotoAndStop(50)
}
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 set preloader(obj:Sprite):void
{
_preloader = obj as Preloader;
_preloader.addEventListener(ProgressEvent.PROGRESS, progressEventHandler);
_preloader.addEventListener(FlexEvent.INIT_COMPLETE,initCompleteEventHandler);
}
public function get stageHeight():Number
{
return 0;
}
public function set stageHeight(value:Number):void
{
}
public function get stageWidth():Number
{
return 0;
}
public function set stageWidth(value:Number):void
{
}
public function initialize():void
{
_loader_mc.x = stage.stageWidth / 2 - _loader_mc.width/2;
_loader_mc.y = stage.stageHeight / 2 - _loader_mc.height/2;
}
private function progressEventHandler(eo:ProgressEvent):void
{
_loader_mc.gotoAndStop(Math.round((eo.bytesLoaded / eo.bytesTotal )*100))
_loader_mc.show_txt.text =Math.round((eo.bytesLoaded / eo.bytesTotal )*100)+" %"
}
private function initCompleteEventHandler(eo:FlexEvent):void{
dispatchEvent(new Event(Event.COMPLETE));
}
}
}
主文件:
<?xml version="1.0" encoding="utf-8"?>
<mx:Application preloader="nPreloader" creationComplete="init()" layout="vertical" xmlns:mx="http://www.adobe.com/2006/mxml" >
<mx:Script>
<![CDATA[
[Embed(source="1.mp3")]
private var _file:Class;
]]>
</mx:Script>
<mx:Button label="Button"/>
<mx:ComboBox ></mx:ComboBox>
<mx:Panel width="250" height="200" layout="absolute">
<mx:Label text="我们是Flex组件,hoho" fontSize="15"/>
</mx:Panel>
</mx:Application>