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

如果Flex页面的高度超过屏幕默认高度的话,有可能application初始化进度条看不到,因为preloader的位置始终是居中的,虽然它事实上是存在的,但是很可能需要将滚动条下拉才能看见,不知情的可能以为页面假死了。下面就介绍如何修改preloader的位置。本文参考了这篇文章

自定义进度条:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
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页面这样写:

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

或者在Flex4里

1
2
3
4
5
<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就以实际高度居中。

来发评论吧~
Powered By Valine
v1.5.2