给Flex的PopUpManager显示控件添加特效
PopUpManager本身不提供显示控件特效设置,对控件的showEffect进行设置似乎不能生效于PopUp显示。实现Popup显示、关闭特效可以简单的封装一个PopUp类来调用PopUpManager,在调用过程中实现自定义的showEffect和hideEffect.
代码
Code
package
{
import flash.display.DisplayObject;
import mx.core.IFlexDisplayObject;
import mx.effects.Blur;
import mx.events.TweenEvent;
import mx.managers.PopUpManager;
public class PopUpEffect
{
public function PopUpEffect()
{
}
public static function Show(control:IFlexDisplayObject,parent:DisplayObject,modal:Boolean=true):void
{
var mShowEffect:Blur=new Blur();
mShowEffect.blurXFrom=255;
mShowEffect.blurYFrom=255;
mShowEffect.blurXTo=0;
mShowEffect.blurYTo=0;
mShowEffect.target= control;
mShowEffect.duration=300;
PopUpManager.addPopUp(control,parent,modal);
PopUpManager.centerPopUp(control);
mShowEffect.play();
}
public static function Hide(control:IFlexDisplayObject):void
{
var mHideEffect:Blur=new Blur();
mHideEffect.blurXFrom=0;
mHideEffect.blurYFrom=0;
mHideEffect.blurXTo=255;
mHideEffect.blurYTo=255;
mHideEffect.addEventListener(TweenEvent.TWEEN_END,function(){
PopUpManager.removePopUp(control);
});
mHideEffect.duration=300;
mHideEffect.target=control;
mHideEffect.play();
}
}
}
package
{
import flash.display.DisplayObject;
import mx.core.IFlexDisplayObject;
import mx.effects.Blur;
import mx.events.TweenEvent;
import mx.managers.PopUpManager;
public class PopUpEffect
{
public function PopUpEffect()
{
}
public static function Show(control:IFlexDisplayObject,parent:DisplayObject,modal:Boolean=true):void
{
var mShowEffect:Blur=new Blur();
mShowEffect.blurXFrom=255;
mShowEffect.blurYFrom=255;
mShowEffect.blurXTo=0;
mShowEffect.blurYTo=0;
mShowEffect.target= control;
mShowEffect.duration=300;
PopUpManager.addPopUp(control,parent,modal);
PopUpManager.centerPopUp(control);
mShowEffect.play();
}
public static function Hide(control:IFlexDisplayObject):void
{
var mHideEffect:Blur=new Blur();
mHideEffect.blurXFrom=0;
mHideEffect.blurYFrom=0;
mHideEffect.blurXTo=255;
mHideEffect.blurYTo=255;
mHideEffect.addEventListener(TweenEvent.TWEEN_END,function(){
PopUpManager.removePopUp(control);
});
mHideEffect.duration=300;
mHideEffect.target=control;
mHideEffect.play();
}
}
}
Code
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
<mx:Script>
<![CDATA[
import PopUpEffect;
]]>
</mx:Script>
<mx:Button label="登陆" horizontalCenter="0" verticalCenter="0">
<mx:click>
<![CDATA[
var frmlogin:Login =new Login();
PopUpEffect.Show(frmlogin,this);
]]>
</mx:click>
</mx:Button>
</mx:Application>
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
<mx:Script>
<![CDATA[
import PopUpEffect;
]]>
</mx:Script>
<mx:Button label="登陆" horizontalCenter="0" verticalCenter="0">
<mx:click>
<![CDATA[
var frmlogin:Login =new Login();
PopUpEffect.Show(frmlogin,this);
]]>
</mx:click>
</mx:Button>
</mx:Application>
Code
<?xml version="1.0" encoding="utf-8"?>
<mx:TitleWindow xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical" width="342" height="172" title="登陆" showCloseButton="true">
<mx:Script>
<![CDATA[
import PopUpEffect;
]]>
</mx:Script>
<mx:Form width="100%">
<mx:FormItem label="用户名:">
<mx:TextInput/>
</mx:FormItem>
<mx:FormItem label="密码:">
<mx:TextInput displayAsPassword="true"/>
</mx:FormItem>
</mx:Form>
<mx:ControlBar height="43" verticalAlign="middle" horizontalAlign="right">
<mx:Button label="确定"/>
<mx:Button label="取消">
<mx:click>
<![CDATA[
PopUpEffect.Hide(this);
]]>
</mx:click>
</mx:Button>
</mx:ControlBar>
<mx:close>
<![CDATA[
PopUpEffect.Hide(this);
]]>
</mx:close>
</mx:TitleWindow>
<?xml version="1.0" encoding="utf-8"?>
<mx:TitleWindow xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical" width="342" height="172" title="登陆" showCloseButton="true">
<mx:Script>
<![CDATA[
import PopUpEffect;
]]>
</mx:Script>
<mx:Form width="100%">
<mx:FormItem label="用户名:">
<mx:TextInput/>
</mx:FormItem>
<mx:FormItem label="密码:">
<mx:TextInput displayAsPassword="true"/>
</mx:FormItem>
</mx:Form>
<mx:ControlBar height="43" verticalAlign="middle" horizontalAlign="right">
<mx:Button label="确定"/>
<mx:Button label="取消">
<mx:click>
<![CDATA[
PopUpEffect.Hide(this);
]]>
</mx:click>
</mx:Button>
</mx:ControlBar>
<mx:close>
<![CDATA[
PopUpEffect.Hide(this);
]]>
</mx:close>
</mx:TitleWindow>