Package COM. zqgame. army. contrl {/*** custom bubble prompt * @ author zhoujie * @ date 2011-8-9 **/import flash. display. displayobject; import flash. display. displayobjectcontainer; import flash. display. sprite; import flash. events. mouseevent; import flash. text. textfield; import flash. text. textfieldautosize; import flash. text. textformat; import flash. utils. dictionary; public class tooltip extends sprite {private var DIC: Diction Ary = New Dictionary (); Private var label: textfield; private VaR _ backgound: SPRITE; Public Function tooltip () {super (); initui ();} static private VaR _ instance: tooltip; static public function getinstance (): tooltip {If (! _ Instance) _ instance = new tooltip (); Return _ instance;} private function regestermodule (Area: *): void {If (area is displayobjectcontainer) {If (DIC [area. name]) return; DIC [area. name] = 1; area. addeventlistener (mouseevent. mouse_over, mousemovefunc); area. addeventlistener (mouseevent. mouse_out, mousemovefunc);} else {var PA: displayobjectcontainer = (area as displayobject ). parent as displayobjectcontainer; If (DIC [PA. name]) Return; DIC [PA. name] = 2; PA. addeventlistener (mouseevent. mouse_over, mousemovefunc); PA. addeventlistener (mouseevent. mouse_out, mousemovefunc) ;}} public function createmediltip (Area: *, mess: string): void {DIC [area. name + "mess"] = mess; regestermodule (area);} private function mousemovefunc (EVT: mouseevent): void {Switch (EVT. type) {Case mouseevent. mouse_out: Hide (EVT); break; Case mouseevent. mouse_over: Show (EVT); break;} p Rivate function hide (EVT: mouseevent): void {This. parent. removechild (this);} private function show (EVT: mouseevent): void {var cont: displayobjectcontainer = EVT. currenttarget as displayobjectcontainer; If (DIC [cont. name] = 2) {var DIS: displayobjectincluevt.tar get as displayobject; If (! Dic [dis. name + "mess" contains invalid return1_label.html text = DIC [dis. name + "mess"]; redraw (5, 5); (EVT. currenttarget as displayobjectcontainer ). addchild (this); this. X = dis. X + 10; this. y = dis. y-10;} else {var OBJ: displayobjectcontainer = EVT. currenttarget as displayobjectcontainer; If (! Dic [obj. name + "mess" contains invalid return1_label.html text = DIC [obj. name + "mess"]; redraw (20, 20); obj. parent. addchild (this); this. X = obj. X + 100; this. y = obj. Y ;}} private function redraw (W: Number, H: Number): void {W + = label. width; H + = label. height; this. graphics. clear (); this. graphics. beginfill (0x000000, 0.4); this. graphics. beginfill (0 xffffff); this. graphics. drawroundrect (0, 0, W, H, 5, 5); this. graphics. endfill ();} private function initui (): void {label = new textfield (); label. autosize = textfieldautosize. left; label. selectable = false; label. multiline = false; label. wordwrap = false; label. defaulttextformat = new textformat ("", 12, 0x666666); label. TEXT = "prompt message"; label. X = 5; label. y = 2; addchild (Label); mouseenabled = mousechildren = false;} public function closetooltip (Area: *): void {If (DIC [area. name]) {Delete DIC [area. name]; Delete DIC [area. name + "mess"];} area. removeeventlistener (mouseevent. mouse_over, mousemovefunc); area. removeeventlistener (mouseevent. mouse_out, mousemovefunc );}}}
It took me one day to write it out. I found a lot of materials on the Internet, but I found that it was not universal and it was very complicated to call it. So I wrote one by myself, you can use only one sentence of code.
Createconltip () calls this method directly, and then transmits the Display object and prompt text. Note that the Display object is any object, which can be a button or MC.