Flex 界面初始化有时那个标准的进度条无法显示,界面长时间会处理空白的状态!我们来自定义一个进度条,

这个进度条加载在 Application 应用程序界面的 <s:Application 标签的 preinitialize 属性上:

  1. preinitialize="preInit(event, '')"

它就可以比 Flex 自执行的正常显示。

1.组件ZtipWindow.mxml

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <s:Group xmlns:fx="http://ns.adobe.com/mxml/2009"
  3. xmlns:s="library://ns.adobe.com/flex/spark"
  4. xmlns:mx="library://ns.adobe.com/flex/mx"
  5. addedEffect="{fadeIn}" removedEffect="{fadeOut}" >
  6.  
  7. <fx:Script>
  8. <![CDATA[
  9. import events.ZTipEvent;
  10.  
  11. import mx.managers.PopUpManager;
  12.  
  13. public var position:Point;
  14.  
  15. [Bindable]
  16. public var icon:Object;
  17.  
  18. [Bindable]
  19. public var message:String;
  20.  
  21. [Bindable]
  22. public var close:Object;
  23.  
  24. override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void
  25. {
  26. if (position)
  27. {
  28. x = position.x - unscaledWidth / 2;
  29. y = position.y - unscaledHeight / 2;
  30. }
  31. super.updateDisplayList(unscaledWidth, unscaledHeight);
  32. }
  33.  
  34. protected function cleTip_clickHandler(event:MouseEvent):void
  35. {
  36. this.dispatchEvent(new ZTipEvent(ZTipEvent.CLOSE));
  37. }
  38.  
  39. public function hideClose():void {
  40. cleTip.visible = false;
  41. cleTip.height = 0;
  42. iconOn.top = 12;
  43. lblOn.top = 10;
  44.  
  45. // if (Number(iconOn.bottom) < 15)
  46. // iconOn.bottom = 15;
  47. }
  48.  
  49. public function showClose():void {
  50. cleTip.visible = true;
  51. cleTip.height = 18;
  52. iconOn.top = 25;
  53. lblOn.top = 32;
  54.  
  55. // if (Number(iconOn.bottom) < 15)
  56. // iconOn.bottom = 15;
  57. }
  58.  
  59. ]]>
  60. </fx:Script>
  61.  
  62. <fx:Declarations>
  63. <s:Fade id="fadeIn" alphaFrom="0" alphaTo="1" duration="1000" />
  64. <s:Fade id="fadeOut" alphaFrom="1" alphaTo="0" duration="2500" />
  65. </fx:Declarations>
  66.  
  67. <s:layout>
  68. <s:BasicLayout/>
  69. </s:layout>
  70.  
  71. <s:BitmapImage left="0" right="0" top="0" bottom="0" source="@Embed(source='assets/skins/alert/tip_bgz.png', scaleGridLeft='5', scaleGridRight='11', scaleGridTop='6', scaleGridBottom='48')" />
  72.  
  73. <s:BitmapImage left="10" top="25" source="{icon}" id="iconOn" />
  74.  
  75. <s:Button top="10" right="10" icon="{close}" click="cleTip_clickHandler(event)" id="cleTip" width="18" height="18" />
  76.  
  77. <s:Label left="45" right="10" top="32" bottom="20" text="{message}" id="lblOn" verticalAlign="middle" />
  78. </s:Group>

2.事件ZTipEvent.as

  1. package events
  2. {
  3. import flash.events.Event;
  4.  
  5. public class ZTipEvent extends Event
  6. {
  7. public static const CLOSE:String = "close";
  8. public var detail:int ;
  9. public function ZTipEvent(type:String, bubbles:Boolean=false, cancelable:Boolean=false, detail:int = -1)
  10. {
  11. super(type, bubbles, cancelable);
  12. this.detail = detail;
  13. }
  14. }
  15. }

3.主程序类Zloading.as

  1. package command
  2. {
  3. import flash.events.MouseEvent;
  4. import flash.geom.Point;
  5. import flash.utils.setTimeout;
  6.  
  7. import components.ZtipWindow;
  8. import events.ZTipEvent;
  9.  
  10. import mx.controls.Alert;
  11. import mx.core.FlexGlobals;
  12. import mx.events.CloseEvent;
  13. import mx.managers.PopUpManager;
  14.  
  15. import spark.components.Application;
  16.  
  17. public class Zloading
  18. {
  19. [Embed('assets/skins/alert/tip_loading.png')]
  20. private static var ICON_LOADING:Class;
  21.  
  22. [Embed(source="assets/skins/icon/icon_delete.png")]
  23. private static var ICON_CLOSE:Class;
  24.  
  25. private static var tip:ZtipWindow = null;
  26. private static var mtip:ZtipWindow = null;
  27. private static var isloading:Boolean = false;
  28. public function Zloading()
  29. {
  30.  
  31. }
  32.  
  33. public static function showTip(message:String, flag:Boolean=true):void {
  34.  
  35. if (isloading && tip && flag) {
  36. PopUpManager.removePopUp(tip);
  37. }
  38.  
  39. isloading = true;
  40. var showX:Number = Application(FlexGlobals.topLevelApplication).width / 2;
  41. var showY:Number = Application(FlexGlobals.topLevelApplication).height / 1.5;
  42. var pos:Point = new Point(showX, showY);
  43. var app:Application = FlexGlobals.topLevelApplication as Application;
  44.  
  45. if (flag || (flag == false && tip == null)) {
  46. tip = new ZtipWindow();
  47. }
  48.  
  49. if(message.length>80)
  50. {
  51. tip.message= message.substr(0,130)+"\r\n"+message.substr(130,message.length-1)
  52. }
  53. else
  54. {
  55. tip.message = message;
  56. }
  57.  
  58. tip.icon = ICON_LOADING;
  59. tip.close = ICON_CLOSE;
  60. tip.hideClose();
  61.  
  62. PopUpManager.addPopUp(tip, app);
  63. PopUpManager.centerPopUp(tip);
  64.  
  65. tip.addEventListener(MouseEvent.MOUSE_DOWN, function():void{
  66. if (!tip)
  67. return;
  68. tip.dispatchEvent(new CloseEvent(CloseEvent.CLOSE));
  69. });
  70. }
  71.  
  72. public static function timeTip(message:String, pos:Point = null, delay:int = 3000):void {
  73.  
  74. if (mtip != null) {
  75. PopUpManager.removePopUp(mtip);
  76. }
  77.  
  78. if(!pos)
  79. {
  80. var showX:Number = Application(FlexGlobals.topLevelApplication).width / 2;
  81. var showY:Number = Application(FlexGlobals.topLevelApplication).height / 1.5;
  82. pos = new Point(showX, showY);
  83. }
  84.  
  85. var app:Application = FlexGlobals.topLevelApplication as Application;
  86.  
  87. mtip = new ZtipWindow();
  88. if(message.length>80)
  89. {
  90. mtip.message= message.substr(0,130)+"\r\n"+message.substr(130,message.length-1)
  91. }
  92. else
  93. {
  94. mtip.message = message;
  95. }
  96.  
  97. mtip.icon = ICON_LOADING;
  98. mtip.position = pos;
  99. mtip.close = ICON_CLOSE;
  100. mtip.hideClose();
  101.  
  102. PopUpManager.addPopUp(mtip, app);
  103. PopUpManager.centerPopUp(mtip);
  104.  
  105. mtip.addEventListener(MouseEvent.MOUSE_DOWN, function():void{
  106. if (!mtip)
  107. return;
  108. mtip.dispatchEvent(new CloseEvent(CloseEvent.CLOSE));
  109. });
  110.  
  111. setTimeout(function():void {
  112. PopUpManager.removePopUp(mtip);
  113. }, delay);
  114. }
  115.  
  116. public static function close(result:String = '数据操作中, 请稍后...', delay:int = 3000):void
  117. {
  118. if (tip != null) {
  119. if (delay != 0) {
  120. setTimeout(function():void {
  121. tip.message = result;
  122. PopUpManager.removePopUp(tip);
  123. isloading = false;
  124. }, delay);
  125. } else {
  126. tip.message = result;
  127. tip.showClose();
  128. tip.addEventListener(ZTipEvent.CLOSE, function():void {
  129. PopUpManager.removePopUp(tip);
  130. isloading = false;
  131. });
  132. }
  133. }
  134. }
  135. }
  136. }

4.调用方法

  1. <s:Application
  2. ...
  3. preinitialize="preInit(event, '')"
  1. private function preInit(event:Event, msg:String):void
  2. {
  3. Zloading.showTip("初始化, 请稍后...");
  4. }

Flex 编写 loading 组件的更多相关文章

  1. Angular23 loading组件、路由配置、子路由配置、路由懒加载配置

    1 需求 由于Angular是单页面的应用,所以在进行数据刷新是进行的局部刷新:在进行数据刷新时从浏览器发出请求到后台响应数据是有时间延迟的,所以在这段时间就需要进行遮罩处理来提示用户系统正在请求数据 ...

  2. vue2.0 仿手机新闻站(五)全局的 loading 组件

    1.组件结构 index.js const LoadingComponent = require('./Loading.vue') const loading = { install: functio ...

  3. ReactJS实践(一)—— FrozenUI React化之Loading组件

    在前面我们通过四篇文章入门了React的大部分主要API,现在则开始进入实践环节. 实践系列的开篇打算拿我司的FrozenUI来试验,将其部分UI组件进行React化,作为第一篇实践文章,将以较简单的 ...

  4. flex的Accordion组件头部文本居中显示

    flex的Accordion组件头部文本默认是居左的,可以通过设置headerStyleName属性使之居中,另外还可以设置字体的样式等 <?xml version="1.0" ...

  5. iOS应用日志:开始编写日志组件与异常日志

    应用日志(一):开始编写日志组件 对于那些做后端开发的工程师来说,看 LOG解Bug应该是理所当然的事,但我接触到的移动应用开发的工程师里面,很多人并没有这个意识,查Bug时总是一遍一遍的试图重现,试 ...

  6. Vue 封装的loading组件

    <template> <div class="loadEffect"> <span></span> <span>< ...

  7. vux 使用 loading 组件

    1)声明引入Loading import { Loading } from 'vux' 2)在模版底部添加 组件(需要添加到 template>div 标签里) <template> ...

  8. 【转载】用纯粹的C++编写COM组件

    原文:http://blog.csdn.net/ghj1976/article/details/3441 下载本文代码 本文提供一个完全用C++实现的进程内(DLL)COM服务器,不要ATL或MFC提 ...

  9. React Native封装Toast与加载Loading组件

    React Native开发封装Toast与加载Loading组件 在App开发中,我们避免不了使用的两个组件,一个Toast,一个网络加载Loading,在RN开发中,也是一样,React Nati ...

随机推荐

  1. Linux第六周学习总结——进程额管理和进程的创建

    Linux第六周学习总结--进程额管理和进程的创建 作者:刘浩晨 [原创作品转载请注明出处] <Linux内核分析>MOOC课程http://mooc.study.163.com/cour ...

  2. 第三次spring冲刺1

    Not Check Out Check Out Done SPRINT GOAL: BETA-READY RELEASE 困难模式   DONE   修改已知bug   DONE   美化界面     ...

  3. 解决eclipse中mybatis的xml配置文件无代码提示问题

    https://blog.csdn.net/IRainReally/article/details/81743506

  4. VSCode和VUE的初始安装及简单使用入门

    (版本1.0) npm run dev 运行工程 PS F:\SDN\VIMS--前端\vue> cnpm install PS F:\SDN\VIMS--前端\vue> cnpm reb ...

  5. PAT 甲级 1096 Consecutive Factors

    https://pintia.cn/problem-sets/994805342720868352/problems/994805370650738688 Among all the factors ...

  6. Delphi中Form的position属性与代码自定义窗体位置

    通过Form的Position属性可设置窗体的初始位置,如选择DesktopCenter为桌面中心,ScreenCenter为屏幕中心,等等. 这个属性在很多时候简化了程序代码. 但是,如果设置了po ...

  7. 【跨域】jsonp跨域实现方法

    封装原生jsonp: 以跨域调取豆瓣电影最热榜单为例: function $jsonp(url,data,callback){ var funcName = 'jsonp_cb' + Math.ran ...

  8. wordApp.Documents.Open 未将对象引用实例

    wordApp.Documents.Open (.........),当我打开的是.docx,能正常打开当是.doc时,却返回空置,显示失败,未能找到文件.......,但其实文件都在 解决方案 WO ...

  9. Luogu4980 【模板】Polya定理(Polya定理+欧拉函数)

    对于置换0→i,1→i+1……,其中包含0的循环的元素个数显然是n/gcd(i,n),由对称性,循环节个数即为gcd(i,n). 那么要求的即为Σngcd(i,n)/n(i=0~n-1,也即1~n). ...

  10. youcompleteme 自动补全

    1. 拷贝配置文件 cp ~/.vim/bundle/YouCompleteMe/cpp/ycm/.ycm_extra_conf.py ~/.vim/.ycm_extra_conf.py 2. 修改配 ...