0
votes

I'm trying to make a button(movieClip-button), that when you hover over it(MOUSE_OVER), it calls a function that displays some text. The only problem is that it doesn't work :p. Or atleast not the way i want it to work. The thing is when i hover over it the first time, nothing displays. If i then remove the mouse from the movieclip and hover over it again it works just fine. Here's my code:

private var priceString:TextField = new TextField();

    private function addText(price:String):void{
        var priceStringFormat = new TextFormat;
        priceStringFormat.color = 0xFF0000;
        priceStringFormat.font = 'TradeGothic';    
        priceStringFormat.size = 30;
        priceString.x = 285;
        priceString.y = 15;
        priceString.setTextFormat(priceStringFormat);
        priceString.autoSize = TextFieldAutoSize.LEFT;
        priceString.text = "Upgrade Costs: " + price;
        getStage.addChild(priceString);
}

I can't myself see the problem:s. Other text fields in the same format in the same class works just fine. The getStage var is holding the stage access. (It works with other text fields). Strange is also that if i try to add a movieclip instead of the textfield, it works just fine.

This is how it should look: http://i.stack.imgur.com/5a0jf.png

2

2 Answers

0
votes

setTextFormat needs to happen after you set the text property. If for whatever reason you need to do the formatting before you set the textFormat, use

priceString.defaultTextFormat = priceStringFormat

0
votes

If you're saying you want to create a tooltip when you hover over a button, you should probably put the TextField into a Sprite object. Add the TextField as a child of the Sprite, and the Sprite as a child of the stage. Then, either tween the alpha value of the Sprite or toggle its visibility using Sprite.visible.

PS: for a detailed tutorial, see:

http://hub.tutsplus.com/tutorials/create-a-customizable-tooltip-in-actionscript-30--active-1793

EDIT:

Based on the image you provided, what you would need is to create a sprite with the TextField as its child in the constructor of your button, and set the sprite's visible property to false.

In your mouseover handler for the button, set the sprite's visible property to true, and in reset it in your mouseout handler.