flex修改application加载进度条preloader的位置

哎查点资料还要科学上网。。。


如果flex页面的高度超过屏幕默认高度的话,有可能application初始化进度条看不到,


因为preloader的位置始终是居中的,虽然它事实上是存在的,但是很可能需要将滚动条下拉


才能看见,不知情的可能以为页面假死了。下面就介绍如何修改preloader的位置。


来源:http://www.mehtanirav.com/2010/03/19/showing-flex-preloader-near-the-top-of-your-application



    自定义进度条:
package com.components
{
  import flash.events.ProgressEvent;
  import mx.preloaders.DownloadProgressBar;

  public class MyDownloadProgressBar extends DownloadProgressBar
  {
    public function MyDownloadProgressBar()
    {
      super();
      // Set the download label.
      downloadingLabel="Downloading..."
      // Set the initialization label.
      initializingLabel="Initializing..."
    }

    // Override to return true so progress bar appears during initialization.
    override protected function showDisplayForInit(elapsedTime:int, count:int):Boolean {
      return true;
    }

    // Override to return true so progress bar appears during download.
    override protected function showDisplayForDownloading(elapsedTime:int, event:ProgressEvent):Boolean {
      return true;
    }

    // Override initialize so that we can position the loader
    override public function initialize():void {
      super.initialize();
      center(stageWidth, (stageHeight > 250) ? 250 : stageHeight);
    }
  }
}



 

   

          在Application页面这样写:

 

 

<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
	preloader="com.components.MyDownloadProgressBar">



 

 

         或者在Flex4里

 

 

<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"
			   xmlns:components="components.*"
			   preloader="components.MyDownloadProgressBar" >


 

  其中关键代initialize函数里的

 

center(stageWidth, (stageHeight > 250) ? 250 : stageHeight),这句的意思是如果屏幕高度超过


  250 pixels,就以250 pixels高度居中,如果屏幕高度低于250 pixels就以实际高度居中。

你可能感兴趣的:(Flex,Flash,Adobe)