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);
Related
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);
I'm having strange problems with positioning of
1) a MovieClip() I've created with AS
2) a textfield inside this MovieClip().
Problem with 1): When I set MC.x = 0; MC.y = 0 the movieClip doesn't appear in the top left corner.
Problem with 2): The text isn't centered vertically nor horizontally.
My AS3 code:
var button:ButtonMC = new ButtonMC();
button.y = 100;
button.x = 100;
button.width = 260;
button.height = 50;
button.buttonMode = true;
button.useHandCursor = true;
button.mouseChildren = false;
var tf:TextFormat = new TextFormat();
tf.size = 70;
tf.bold = true;
tf.font = "Arial"
tf.color = 0xFFFFFF;
var myText:TextField = new TextField();
myText.defaultTextFormat = tf;
myText.autoSize = TextFieldAutoSize.CENTER;
button.addChild(myText);
myText.text = 'ThisIsATestText1234';
myText.y = button.height * 0.5 - myText.textHeight * 0.5;
addChild(button);
Since myText is already added to the button at the point where you try to get the height of the button it might screw up the calculation. Try to align the textfield first and the add it to the button.
You are also changing the width and height of the Button which changes the scale and therefor also affects how the textfield inside looks like and behaves (since it will become a child of the button)
Best way to tackle both problems at once is to create a background-clip within the button and give that the proper size. Then create the textfield and adjust it's scale according to the background. This way the button remains it original scale and won't mess up the stuff that's inside it.
Hope this helps.
PS: useHandCursor = true is not needed when you set buttonMode = true ;)
remove those lines:
button.width = 260;
button.height = 50;
and you will have easier to position text - also the buttons height is affected by added textfield so better use fixed value e.g.
myText.y = 25 - (myText.height * 0.5);
I've a problem to change the font-color of a TextField after it has been added as a child to a MovieClip.
My code:
var btn:MovieClip = new MovieClip();
// other code for button
var tf:TextFormat = new TextFormat();
tf.size = 12;
tf.bold = true;
tf.font = "Arial"
tf.color = 0x000000;
var capt:TextField = new TextField();
capt.defaultTextFormat = tf;
capt.width = 200;
capt.height = 50;
capt.text = "Test";
capt.y = 20;
capt.x = 20;
capt.border = false;
capt.selectable = false;
btn.addChild(capt);
// .....
How can I Change the font-color after the last line?
It sounds like you're looking for TextField.setTextFormat(). You can either adjust your original TextFormat or just make a whole new one.
tf.color = 0xFF0000;
capt.setTextFormat(tf);
Assuming the TextField falls out of scope after that last line (you don't show enough to know if it does or not), you'll need to loop through the button to get the TextField and do it from there.
var i:uint;
var l:uint = btn.numChildren; //numChildren and length are 'heavy' getters, never use them as restrictors in a loop
for ( i = 0; i < l; i++ ) {
var cur:DisplayObject = btn.getChildAt( i );
if ( cur is TextField ) {
( cur as TextField ).setTextFormat( /*set new TextFormat in here*/);
break;
}
}
That assumes there is only the single TextField, of course. If there are multiple, I would extend MovieClip and add a public property for the value you want to change.
You can also just use the textColor property of a textfield:
capt.textColor = 0xFF0000;
In a card game I use a TextField in the middle to display the playing table number, but also to detect if a playing card has been played - using myTextField.hitTestObject(myCard) - which means the TextField's position and dimensions may not change:
My current AS3 code is:
var format:TextFormat = new TextFormat();
format.color = 0xFFFFFF;
format.size = 30;
format.bold = true;
myTextField.defaultTextFormat = format;
myTextField.border = true;
myTextField.borderColor = 0xFFFFFF;
myTextField.x = W/2-Card.W/2;
myTextField.y = Card.H;
myTextField.width = Card.W;
myTextField.height = Card.H/4;
addChild(myTextField);
However the TextField's content (the String "#2029" in the above screenshot) is not in the center of it.
I can not set _middle.autoSize = TextFieldAutoSize.CENTER because this changes the width of the border and breaks hitTestObject().
Is there another way to align the text in the middle please?
Set the align property of TextFormat.
format.align = TextFormatAlign.CENTER;
How can I set the properties for the text outline / border for each character in a line of text in AS3 ?
I don't think you can. What you can do is use a blur filter to mimic the appearance of an outline. Just paste this into an empty AS3 movie:
var txt:TextField = new TextField();
this.addChild(txt);
txt.appendText('Lorem ipsum');
txt.autoSize = TextFieldAutoSize.LEFT;
txt.antiAliasType = flash.text.AntiAliasType.NORMAL;
txt.selectable = false;
var txtFormat:TextFormat = new TextFormat();
txtFormat.size = 40;
txtFormat.font = 'Helvetica';
txt.setTextFormat(txtFormat);
txt.defaultTextFormat = txtFormat;
var outline:GlowFilter = new GlowFilter();
outline.blurX = outline.blurY = 1;
outline.color = 0xFF0000;
outline.quality = BitmapFilterQuality.HIGH;
outline.strength = 100;
var filterArray:Array = new Array();
filterArray.push(outline);
txt.filters = filterArray;
Try playing with the strength, blurX, blurY and quality properties, in order to obtain different appearances. I think that's about the closest you can get to a text outline.
PS: font embedding would greatly improve the quality of the effect, as well as making the antialias work properly.
i am not shore i understand but you can use same kind of
filter on the testbox and by doing so you can get a same kind of a border
in each one of your letters