Disabled Button loses TextFormat - actionscript-3

I have a button with a custom textformat that I set via the setStyle method such as:
var tf:TextFormat = new TextFormat();
tf.font = "Arial";
var button:Button = new Button();
button.setStyle("textFormat", tf);
button.label = "Click Me";
However when this button is disabled it loses its textFormat. Reseting the text format after disabling the button does not affect it.
What can I do to still apply the textformat to a disabled button?
Thanks in advance.

I believe you could access textField of the button.
Then use defaultTextFormat instead of setTextFormat.
var tf:TextFormat = new TextFormat();
tf.font = "Arial";
my_textBox.defaultTextFormat = tf;
Apparently above wont work, but this would :
button.setStyle("disabledTextFormat", tf);

Related

How can I change the size in TextField AS3?

I'm doing a game and would like to increase the size of the score since it's too small
Thanks for the answer
This is the code for the score:
var score_txt:TextField=new TextField();
score_txt.textColor=0xFFFFFF;
score_txt.x=142,3;
score_txt.y=563,05;
note:the score must be TextField not TextFormat
have you tried this?
score_txt.width = 100;
score_txt.height = 100;
Using a TextFormat could be easier:
var myFormat:TextFormat = new TextFormat();
myFormat.size = 15;
score_txt.defaultTextFormat = myFormat;
score_txt.text = "your text"

AS3 / Why does my label change if i disable it? (Radiobutton)

Why changed my label color and size when I disable it? And how would I be able to solve it?
And if this is not possible, how would I then be able to resolve it the best?
You need to edit disabled state clip of your radio button component. Double click on your radio button then you will see all the states of it as in the image
Change the graphics as you want.
Hope it helps.
Try this,
var hit:RadioButton = event.currentTarget as RadioButton;
var format:TextFormat = new TextFormat();
format.font = "Arial";
format.size = 23;
format.bold = false;
format.color = 0x5D205E;
format.letterSpacing = 0;
hit.label = " Hello";
hit.setStyle("textFormat", format);

Try to mask a textfield in actionscript

I trying to mask a textField with the following code, but it's not working.
var Blue_clip:blue_img = new blue_img()
addChild(Blue_clip)
var field:TextField=new TextField();
var format:TextFormat=new TextFormat();
format.size = 40;
format.font = "Arial";
field.defaultTextFormat = format;
field.text = "Hello World";
addChild(field);
Blue_clip.mask = field;
Please guide me.
Method 1) - Use runtime AS mask
_root.attachMovie("mask", "mask_instance", 3 ,{_x:10, _y:20});
_root.masked_content_mc.setMask(mask_instance);
where mask is AS exported movie clip in lybrary (simple shape 100x100px for example)
Method 2) - Embed font.
You have to embed the font using Text->Font Embedding and then set it to the text field:
var style_tf:TextFormat = new TextFormat();
style_tf.font = "ArialEmbed";
style_tf.size = 16;
_root.my_text.setTextFormat(style_tf);

actionscript transparent textinput background

after hours of search I successfully set my font color to yellow, but I still can`t figure out how to make my background of textinput transparent :(
(I dragged it out of the component window)
What is wrong with my code?
var tf:TextFormat = new TextFormat();
tf.size = 10;
tf.color = 0xFFF000;
nameField.setStyle("textFormat", tf);
nameField.alpha = 0;
TextInput has styles contentBackgroundAlpha and contentBackgroundColor.
nameField.setStyle("contentBackgroundAlpha", 0);
P.S. It is if you use FLEX.
nameField.background = false; you should check the docs.
as in following example
var input:TextField = new TextField();
input.textColor = 0xFFFF00;
input.background = false;
input.backgroundColor = 0x000000;//this is to show that the background is not visible - you can put any colour other than SWF's background:)
input.type = TextFieldType.INPUT;
addChild(input);

AS3. EventListener.Click depends on position

I'm doing a button on AS3 made out of a sprite wich (just a simple square). When I add the event listener so that it acts as a button it works but depending on button.x, so when I put the button where I want the button stops working.
Thanks
public function pintaInterficieTrad(){
while(numChildren != 0) removeChildAt(0);
var idioma = new TextField();
idioma.text=traductor.*[numTrad].*;
idioma.width=200;
idioma.selectable=false;
idioma.setTextFormat(format);
idioma.x=20;
idioma.y=20;
addChild(idioma);
var trad = new Sprite();
trad.graphics.lineStyle(5,0x00ff00);
trad.graphics.beginFill(0x000000);
trad.graphics.drawRect(300,20,150,70);
addChild(trad);
var textTrad = new TextField();
if(numTrad==0) {
textTrad.text="Traduir";
}else{
textTrad.text="Traducir";
}
textTrad.width=200;
textTrad.selectable=false;
textTrad.setTextFormat(format);
textTrad.x=270;
textTrad.y=40;
addChild(textTrad);
var getBack = new Sprite();
getBack.graphics.lineStyle(5,0x00ff00);
getBack.graphics.beginFill(0x000000);
getBack.graphics.drawRect(500,20,150,70);
addChild(getBack);
var textgetBack = new TextField();
if(numTrad==0) {
textgetBack.text="Tornar";
}else{
textgetBack.text="Volver";
}
textgetBack.width=200;
textgetBack.selectable=false;
textgetBack.setTextFormat(format);
textgetBack.x=470;
textgetBack.y=40;
addChild(textgetBack);
trad.addEventListener(MouseEvent.CLICK,traduirBtn);
getBack.addEventListener(MouseEvent.CLICK,tornarBtn);
var userBox = new Sprite();
userBox.graphics.lineStyle(2,0x00ff00);
userBox.graphics.beginFill(0xffffff);
userBox.graphics.drawRect(40,130,610,160);
addChild(userBox);
var tradBox = new Sprite();
tradBox.graphics.lineStyle(2,0x00ff00);
tradBox.graphics.beginFill(0xffffff);
tradBox.graphics.drawRect(40,320,610,160);
addChild(tradBox);
var formatTxt = new TextFormat();
formatTxt.color=0x000000;
formatTxt.size=14;
var textUser = new TextField();
var textTraduit = new TextField();
textUser.defaultTextFormat=formatTxt;
textUser.text = textUsuari;
textUser.width = 600;
textUser.height = 150;
textUser.x=45;
textUser.y=130;
addChild(textUser);
textTraduit.text = traduccio;
textTraduit.setTextFormat(formatTxt);
textTraduit.width = 600;
textTraduit.height = 150;
textTraduit.x=45;
textTraduit.y=325;
addChild(textTraduit);
}
public function traduirBtn(e){
while(numChildren != 0) removeChildAt(0);
tradueix();
pintaInterficieTrad();
}
public function tornarBtn(e){
while(numChildren != 0) removeChildAt(0);
pintaMenu();
}
}
If I put the squares on x=0 they do what they're suposed to do...
seems like the button you're talking about is trad. You're addChilding it quite early in your code, which means that antoher displayobject could get above it at the same position. When you click at that position, the click event will only get send to the top most element, so try adding the elements you want people to interact with as the last (buttons, text field inputs, etc.)
Your problem is in the fact that you are adding the text over the button and the text is being clicked, not the button.
Add the text to the button itself and your click event will work.
Also verify that no other component is covering the button. Even if transparent, like a textbox.