您的位置:首页 > 其它

Adobe Flex迷你教程 — Super easy实现Mac系统下滑式Alert窗口

2013-02-28 13:35 429 查看
这段code是参考kevin先生的,我简单做了修改。

package comalert
{
import flash.display.DisplayObject;
import flash.display.Sprite;

import mx.controls.Alert;
import mx.core.Application;
import mx.core.FlexGlobals;
import mx.effects.Move;
import mx.effects.Parallel;
import mx.effects.WipeDown;
import mx.effects.WipeUp;
import mx.managers.PopUpManager;

public class KAlert
{
public function KAlert()
{
}
public static function show(text:String,modal:Boolean = false):void{
var alert:Alert = new Alert();

//setAppleStyle(alert);
setOpenEffect(alert);

alert.text = text;
var parent:Sprite = Sprite(FlexGlobals.topLevelApplication);
alert.x = FlexGlobals.topLevelApplication.width/2-100;

PopUpManager.addPopUp(alert, parent, modal);

alert.setActualSize(alert.getExplicitOrMeasuredWidth(), alert.getExplicitOrMeasuredHeight());

}
private static function setOpenEffect(alert:Alert):void{
var wipeUp:WipeUp = new WipeUp(); //Wipe效果,方向向上
var move:Move = new Move(); //移定效果
var parallel:Parallel = new Parallel(); //加入其中的效果会被并发执行
parallel.addChild(move);
parallel.addChild(wipeUp);

//设置弹出框在正中央
move.xFrom = FlexGlobals.topLevelApplication.width/2-100;
move.xTo = FlexGlobals.topLevelApplication.width/2-100;

//弹出时从-100移动到100,同时wipeUp
move.yFrom = 100;
move.yTo = 200;
//动画执行时间为300毫秒
wipeUp.duration = 1000;
move.duration=1000;
//在当前控件被加入舞台时执行
alert.setStyle("addedEffect",parallel)
}
}
}


下面为主应用程序的代码

<?xml version="1.0" encoding="utf-8"?>
<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" minWidth="955" minHeight="600">

<fx:Script>
<![CDATA[
import comalert.KAlert;
protected function button1_clickHandler(event:MouseEvent):void
{
// TODO Auto-generated method stub
KAlert.show("Test Slide Effect");
}
]]>
</fx:Script>

<fx:Declarations>
<!-- 将非可视元素(例如服务、值对象)放在此处 -->
</fx:Declarations>
<s:Button id="SlideAlert" click="button1_clickHandler(event)"/>

</s:Application>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: