package com.pgworld.util { import flash.display.Sprite; import flash.events.MouseEvent; import flash.events.TimerEvent; import flash.text.TextField; import flash.text.TextFieldAutoSize; import flash.text.TextFormat; import flash.text.TextFormatAlign; import flash.utils.Timer; /** * @author Administrator */ public class FTimerAlertFont extends Sprite { private var sp : Sprite = new Sprite(); public var _textField : TextField; private var timer : Timer; public function FTimerAlertFont(text : String, width : int) { _textField = new TextField(); // _textField.border = true; _textField.width = width; _textField.wordWrap = true; _textField.text = text; _textField.autoSize = TextFieldAutoSize.LEFT; _textField.mouseEnabled = false; _textField.selectable = false; var format : TextFormat = new TextFormat(); format.font = "宋体"; format.size = 12; format.color = 0xffffff; format.align = TextFormatAlign.LEFT; _textField.setTextFormat(format); sp.graphics.lineStyle(1, 0xfafcc9, 1, true); sp.addEventListener(MouseEvent.CLICK, onClick); sp.graphics.beginFill(0x000000, .6); sp.graphics.drawRoundRect(-5, -5, _textField.textWidth + 50 - 37, _textField.textHeight + 50 - 40, 7); sp.graphics.endFill(); sp.addChild(_textField); sp.y = -_textField.height; this.addChild(sp); timer = new Timer(5000, 1); timer.start(); timer.addEventListener("timer", listener); } private function onClick(e : MouseEvent) : void { if (timer != null) { timer.stop(); close(); } } public function close() : void { SpriteUtil.remove(this); } private function listener(e : TimerEvent) : void { var timer : Timer = e.target as Timer; timer.stop(); timer.removeEventListener("timer", listener); close(); } } } 测试Main var ftimerAlert : FTimerAlertFont = new FTimerAlertFont("失败则当日不可再次挑战次日可继续挑战0关会有珍宝八卦鼎奖次日可继续挑战次日可继续挑战", 69); ftimerAlert.name = "FTimerAlertFont"; ftimerAlert.x = 100; ftimerAlert.y = 100; this.addChild(ftimerAlert);