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