2011-09-21 75 views
0

這裏有一塊類,它在我已經繪製了一些對象後調用,問題是當我有sprite.addChild(textfield)包含它開始閃爍很多。actionscript閃爍工具提示時addChild(textfield);

 addEventListener(MouseEvent.MOUSE_OVER, mouseOverHandler); 
     addEventListener(MouseEvent.MOUSE_OUT, mouseOutHandler); 
     addEventListener(MouseEvent.MOUSE_MOVE, mouseMoveHandler); 

     } 



      private function mouseOverHandler(e:MouseEvent):void{ 
       //creating a new tooltip instance 
       var tooltip:Sprite = new Sprite(); 
       /*//we tell the holder to hold our tooltip 
     holder = tooltip; 
     //adding text to the tooltip 
     //tooltip.myText = "ASS"; 
     //positioning the tooltip on the stage 
     holder.x = stage.mouseX; 
     holder.y = stage.mouseY - 15; 
     //adding the tooltip to the stage*/ 
       textfield.selectable = false; 
     textformat.align = TextFormatAlign.CENTER; 
     textformat.size = 12; 
     textformat.color = 0x000000; 
     textfield.defaultTextFormat = textformat; 
     textfield.x = x; 
     textfield.y = y; 
     textfield.width = width; 
     textfield.height = height; 
     textfield.text = myName; 
     sprite.graphics.lineStyle(2,0x00BB00); 
     sprite.graphics.beginFill(0xFFFFFF, 1); 
     sprite.graphics.drawRect(x, y, width, height); 
     sprite.graphics.endFill(); 
     sprite.addChild(textfield); 
     sprite.x = stage.mouseX; 
     sprite.y = stage.mouseY - 15; 
     tooltip.addChild(sprite); 
       //holder.addChild(tooltip); 
     addChild(sprite) 
     } 

      private function mouseOutHandler(e:MouseEvent):void{ 
       //we remove the holder when the cursor is outside our button 
     removeChild(sprite); 
     } 

      //we create this function to move the tooltip everytime the cursor is moved 
      private function mouseMoveHandler(e:MouseEvent):void{ 
     sprite.x = stage.mouseX; 
     sprite.y = stage.mouseY - 15; 
     } 

回答

0

即使我不確定,這可能會解釋您的問題。您可以提供更多信息以獲得更好的解決方當你添加精靈時,它會調用mouseOutHandler,導致你在你的光標下添加你的精靈,並且你使用removeChild(精靈)去除精靈;並且mouseOverHandler再次調用它。

+0

已經修復它。實際上,添加和刪除不是很正確,因爲我正在完成整個類內的工具提示例程。我基本上用sprite.visible替換addchild/removechild true/false – Smoke