<h1 class="ts">怎么关闭所有popupmanager弹出的窗口?</h1>
这一个貌似很简单,缺又凭空增加麻烦和工作量的事情.
如果你按照下面这种模式,那么关闭所有弹出窗口又变得那么简单.
需求: 假设当应用程序出现错误.需要将用户弹出窗口全部关闭.恢复到初始状态.
实现思路:
1. 定义单例类. 用来保存所有弹出窗口的数组
2. 将弹出事件封装,由其去创建弹出窗口.和保存到数组对象
两个重要类:
popupeffect.as(弹出事件封装类)
popupmodellocator.as (保存数组对象的单例类,关闭全部调用)
使用方法:
a. 弹出窗口创建入口: popupeffect.show
c. 弹出窗口全部关闭调用: popall - 注意是popupmodellocator的方法
依赖类库:
as3corelib.swc
工程编译是用sdk3.5编译的. 你可以修改成4 因为都是as文件.完全向上兼容.
<br><img src="http://dl.iteye.com/upload/attachment/491928/2c6ca20c-41fc-3267-8494-04492a926d17.png" alt="">
这一个貌似很简单,缺又凭空增加麻烦和工作量的事情.
如果你按照下面这种模式,那么关闭所有弹出窗口又变得那么简单.
需求: 假设当应用程序出现错误.需要将用户弹出窗口全部关闭.恢复到初始状态.
实现思路:
1. 定义单例类. 用来保存所有弹出窗口的数组
2. 将弹出事件封装,由其去创建弹出窗口.和保存到数组对象
两个重要类:
popupeffect.as(弹出事件封装类)
package com.javaeye.jhaij{ import mx.managers.popupmanager; public class popupeffect { public function popupeffect() { } public static function show(parent:*,control:*,modal:boolean=false):void { popupmanager.addpopup(control,parent,modal); popupmanager.centerpopup(control); popupmodellocator.getinstance().push(control); } public static function hide(control:*):void { popupmanager.removepopup(control); popupmodellocator.getinstance().pop(control); } } }
popupmodellocator.as (保存数组对象的单例类,关闭全部调用)
package com.javaeye.jhaij{ import com.adobe.utils.arrayutil; [bindable] public class popupmodellocator { private static var instance:popupmodellocator; //保存pop出来的窗口 private var popuparray:array ; public function datagridmodellocator() { if(instance==null){ instance = this; } } public static function getinstance():popupmodellocator{ if(instance==null){ instance = new popupmodellocator(); } return instance; } public function push(control:*):void{ if(!popuparray){ popuparray = new array; } popuparray.push(control); } public function pop(control:*):void{ if(popuparray){ arrayutil.removevaluefromarray(popuparray,control); } } public function popall():void{ if(popuparray&&popuparray.length>0){ popupeffect.hide(popuparray[popuparray.length-1]); popall(); }else{ return; } } }}
使用方法:
a. 弹出窗口创建入口: popupeffect.show
var p:popwindow = new popwindow; popupeffect.show(this,p); p.setfocus();
b. 弹出窗口单个关闭调用: popupeffect.hide
close="popupeffect.hide(this);"
c. 弹出窗口全部关闭调用: popall - 注意是popupmodellocator的方法
popupmodellocator.getinstance().popall();
依赖类库:
as3corelib.swc
工程编译是用sdk3.5编译的. 你可以修改成4 因为都是as文件.完全向上兼容.
<br><img src="http://dl.iteye.com/upload/attachment/491928/2c6ca20c-41fc-3267-8494-04492a926d17.png" alt="">