提示信息通常使用Alert组件就OK了.但是有时候想个性化一些,比方说在提示出现与移除时加些效果,或者让Alert定时消失等.使用Alert组件实现这些有些麻烦,要对其扩展.
找个容易上手的方法,自己写了个,呵呵
模仿Alert的形式,调用类静态方法,不用实例化,这里命名为AlertTip
使用Canvas作为基本容器,包含Text组件
考虑到若将Canvas及Text放置到AlertTip中生成过于复杂,所以将Canvas容器单独做为一个component来供AlertTip使用.
Canvas容器,这里命名为AlertCanvas
使用PopUpManager显示
示例:
Flash动画代码:
点击查看AlertCanvas.mxml文件
说明一点,把Canvas的visible属性设置为false是因为显示前AlertTip是不可见的.
主类,AlertTip
点击查看AlertTip.as文件
[code]
/**
* By AuZn
* Kingnare.com
*/
package com.kingnare {
import mx.core.IFlexDisplayObject;
import mx.managers.PopUpManager;
import flash.display.Sprite;
import mx.core.Application;
public class AlertTip{
public static var globalDelay:uint = 1000;
public function AlertTip(){
}
/**
* 提示显示方法
* message:提示信息
* delay:可显示的时间
* modal:背景变灰
* initValue:初始化数值
* parent:父级
*/
public static function show(message:String="", delay:int=-1, modal:Boolean=false, initValue:Object=null, parent:Sprite=null):void{
if(delay<0) delay = globalDelay;
if (!parent) parent = Sprite(Application.application);
var alert:IFlexDisplayObject = PopUpManager.createPopUp(parent, AlertCanvas, modal);
AlertCanvas(alert).msg = message;
AlertCanvas(alert).delay = delay;
AlertCanvas(alert).init = initValue;
PopUpManager.centerPopUp(alert);
}
}
}
[/code]
示例代码(Demo): AlertTipApp
[code]
xmlns:kingnare="com.kingnare.*"
backgroundGradientColors="[#666666, #C0C0C0]">
import com.kingnare.*;
private function showTip():void{
AlertTip.show("Hello World",
1000,
false,
{width:220, height:120, style:"AlertTip"}
);
}
]]>
.AlertTip{
backgroundColor: #000000;
backgroundAlpha: 0.6;
borderStyle: "solid";
borderColor: #DDDDDD;
cornerRadius: 4;
dropShadowColor: #000000;
dropShadowEnabled: true;
shadowDirection: "center";
shadowDistance: 1;
color: #00FFFF;
textAlign: "center";
fontSize: 12;
}
[/code]
其中的AlertTip为提示窗口的样式
功能很有限,只起到个提示作用.
要扩展成Alert那样有标题及按钮的估计就不能用Canvas组件了,用Panel组件扩展起来容易些
还要加上事件处理,呵呵
源代码打包:
AlertTip.zip


AlertCanvas是什么东东啊 报错?? 代码能贴完么 感觉做的挺不错的 分享一下呢
[reply=auzn,2009-08-24 08:40 AM]代码已经共享了, 文章最后一行有下载地址
AlertCanvas文章中也有提到. 出的错误是什么呢?[/reply]
[Reply]
@KK:
[lol]
[Reply]
正好解我燃眉之急,3Q.
[Reply]
[razz]
[Reply]
谢谢,收藏,我需要这方面的资料
[Reply]