+Rich Internet Applications with Adobe Flex & Java – SYS-CON Books学习进程——自定义加载条

终于康复了,热伤风还真是难缠呀,还好,经过锻炼终于康复了,在下一个月里开始系统的学习FLEX,在这里也将提炼出我遇到的问题的解决。有兴趣的可以常来逛逛这里,希望对你有帮助。

你是否已经厌倦了朴实的加载条,迫不及待的想换换了,那就看看下面的例子,你就将拥有自己的加载条了。

MXML中的关键点

<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" 
preloader="mycomponents.mydownloadbar">//这里的mycomponents.mydownloadbar就是
你要体现的加载条的类。同时下面的是不显示加载条
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" 
usePreloader="false">//usePreloader属性是是否使用加载条

基本加载条的形成代码:

package myComponents
{
    import mx.preloaders.*; 
    import flash.events.ProgressEvent;

    public class DownloadProgressBarSubClassMin extends DownloadProgressBar
    {
        public function DownloadProgressBarSubClassMin()
        {   
            super();
            // 设置下载的提示文字
            downloadingLabel="Downloading app..."
            // 设置初试化的提示文字
            initializingLabel="Initializing app..."
            // 设置最小的显示时间
            MINIMUM_DISPLAY_TIME=2000;
        }
        
        // 覆盖显示属性为真,这样加载条显示
        // 在初始化期间.       
        override protected function showDisplayForInit(elapsedTime:int, 
            count:int):Boolean {
                return true;
        }

        // 下载情况显示条属性为真,这样下载过程中显示加载条.     
        override protected function showDisplayForDownloading(
            elapsedTime:int, event:ProgressEvent):Boolean {
                return true;
        }
    }
}
//加载自定义加载条
<?xml version="1.0"?> 
<!-- containersapplicationMainDPBMin.mxml -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" 
    preloader="myComponents.DownloadProgressBarSubClassMin">

    <mx:Button/>
</mx:Application>
 
进阶-这个还不是我想要的,我想要加载条显示的是我自己的一段动画
//下面代码相信可以满足我们(当然灵活运用可以衍生出更多的漂亮加载条)

package myComponents
{
    import flash.display.Sprite;
    import mx.preloaders.IPreloaderDisplay;
    import flash.events.Event;
    import flash.events.ProgressEvent;
    import flash.events.TimerEvent;
    import flash.net.URLRequest;
    import flash.utils.Timer;
    import mx.events.FlexEvent;
    public class MyDownloadProgressBarSWF extends Sprite
        implements IPreloaderDisplay
    {
        // 定义一个加载SWF的容器.
        private var dpbImageControl:flash.display.Loader;
        public function MyDownloadProgressBarSWF() {  
            super();       
        }
        // 指定事件监听.
        public function set preloader(preloader:Sprite):void {
            // Listen for the relevant events
            preloader.addEventListener(
                ProgressEvent.PROGRESS, handleProgress);
            preloader.addEventListener(
                Event.COMPLETE, handleComplete);
            preloader.addEventListener(
                FlexEvent.INIT_PROGRESS, handleInitProgress);
            preloader.addEventListener(
                FlexEvent.INIT_COMPLETE, handleInitComplete);
        }
        // 初始化LOAD容器事件重新定义IPreloaderDisplay.initialize()事件
        public function initialize():void {
            dpbImageControl = new flash.display.Loader();      
            dpbImageControl.contentLoaderInfo.addEventListener(
                Event.COMPLETE, loader_completeHandler);
            dpbImageControl.load(new URLRequest("assets/dpbSWF.swf"));        
        }

        // 当SWF读取以后,定义读取SWF容器的大小.
        private function loader_completeHandler(event:Event):void
        {
            addChild(dpbImageControl);
            dpbImageControl.width = 50;
            dpbImageControl.height= 50;
            dpbImageControl.x = 100;
            dpbImageControl.y = 100;
        }  
        // 定义空的事件监听.
        private function handleProgress(event:ProgressEvent):void {
        }
        private function handleComplete(event:Event):void {
        }
        private function handleInitProgress(event:Event):void {
        }
        private function handleInitComplete(event:Event):void {
            var timer:Timer = new Timer(2000,1);
            timer.addEventListener(TimerEvent.TIMER, dispatchComplete);
            timer.start();     
        }
        private function dispatchComplete(event:TimerEvent):void {
            dispatchEvent(new Event(Event.COMPLETE));
        }

        // 执行 IPreloaderDisplay 类接口
        public function get backgroundColor():uint {
            return 0;
        }
        public function set backgroundColor(value:uint):void {
        }
        public function get backgroundAlpha():Number {
            return 0;
        }
        public function set backgroundAlpha(value:Number):void {
        }
        public function get backgroundImage():Object {
            return undefined;
        }
        public function set backgroundImage(value:Object):void {
        }
        public function get backgroundSize():String {
            return "";
        }
        public function set backgroundSize(value:String):void {
        }
        public function get stageWidth():Number {
            return 200;
        }
        public function set stageWidth(value:Number):void {
        }
        public function get stageHeight():Number {
            return 200;
        }
        public function set stageHeight(value:Number):void {
        }
    }

}

MXML加载LOADING控件

<?xml version="1.0"?>
<!– containersapplicationMainDPBMin.mxml –>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
    preloader="myComponents.MyDownloadProgressBarSWF">

    <mx:Button/>
    <mx:TextInput text="sub class min" />
</mx:Application>

Advertisements

2 responses to this post.

  1. Posted by Lily on 九月 13, 2007 at 6:32 上午

     教程,踩踩

    回复

  2. Posted by 巴鲁 on 九月 15, 2007 at 5:09 上午

    哎,怎么好多脚印呀!

    回复

发表评论

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / 更改 )

Twitter picture

You are commenting using your Twitter account. Log Out / 更改 )

Facebook photo

You are commenting using your Facebook account. Log Out / 更改 )

Google+ photo

You are commenting using your Google+ account. Log Out / 更改 )

Connecting to %s

%d 博主赞过: