给Flex的PopUpManager显示控件添加特效

PopUpEffect.as
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();
}
}
}

 

main.mxml
<?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>

 

Login.mxml
<?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>

 

posted @ 2011-01-11 10:26  TsengYuen  阅读(731)  评论(0编辑  收藏  举报