Here's my Code
var format:TextFormat=new TextFormat();
var text:TextField=new TextField();
text.border=true;
text.width=400;
text.multiline=true;
text.wordWrap=true;
text.type=TextFieldType.INPUT;
text.background=true;
text.text="Some text"; // Bold doesn't works with this line
format.bold=true;
text.defaultTextFormat=format;
I can't format text in INPUT textfield when it isn't EMPTY.How i can solve this problem or what is my mistake?
The problem is in defaultTextFormat. As reference says it
specifies the format applied to newly inserted text, such as text
entered by a user or text inserted with the replaceSelectedText()
method.
Try to use a text.setTextFormat(format); instead.
Try to call setTextFormat, you may see this post
text.defaultTextFormat=format;
text.setTextFormat(format);
First set defaultTextFormat, then set text.
format.bold=true;
text.defaultTextFormat=format;
text.text="Some text"; // Should now be bold
Related
I have the textarea "write_t". I use following code to change the value of textarea. The problem is '
' does not help me to add the new line. What do I wrong?
var el =document.forms[0].write_t;
el.value=el.value+'
'+k+" some text";
Use \n to add a new line.
var el =document.forms[0].write_t;
el.value=el.value+'
'+k+"\nsome text";
I am creating a simple flash animation that displays text in a textField(textBox?).
var fl_TextLoader:URLLoader = new URLLoader();
var fl_TextURLRequest:URLRequest = new URLRequest("./liveStatus.txt");
fl_TextLoader.addEventListener(Event.COMPLETE, fl_CompleteHandler);
function fl_CompleteHandler(event:Event):void
{
var textData:String = new String(fl_TextLoader.data);
trace(textData);
text_feed_1.text_feed_1_text.text = textData;
}
However, when the text file has multiple lines, the text that gets displayed only contains the first line of that file, while the "trace" method displays everything in the console output. So I wonder how to display the additional lines from that text file in the textField.
Also, it would be great if these lines can be parsed into a string array. That would be even better because I can then manipulate the lines of that file.
Thank you very much!
Try to set the "multiline" (and maybe "wordWrap") value from your Textfield to true.
http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/text/TextField.html
An to parse your string in a array you could use the split method from String like so:
var linesArray:Array = fl_TextLoader.data.split("\n");
\n = new line char. ("\r" or "\r\n" might alos do the trick depending on the encoding of your text file)
In actionScript,am trying to change the text area using setSize()here is the code..please help me
var prbDesc_txt:TextArea = new TextArea();
prbDesc_txt.text = "Hello world!";
reportAProblemPopUp.addChild(prbDesc_txt);
reportAProblemPopUp.prbDesc_txt.setSize(100,100);
Here am trying to add the textarea to reportAProblemPopUpmc.
Instead of:
reportAProblemPopUp.prbDesc_txt.setSize(100,100);
remove the reportAProblemPopUp and just reference it directly:
prbDesc_txt.setSize(100,100);
Otherwise you need to use getChildByName() on your reportAProblemPopUp if you want to reference it the way you were thinking of.
I have a function which updates my dynamic fields, but nothing happens...any ideas on what could be wrong?
function updateBar(){
progressBar.scaleX = percentToLevel;
levelText.text = level.toString();
expText.text = String(currentExp);
nextLvlText.text = String(baseLevelExp);
}
The progressBar line works. The rest don't. No errors. I checked the instance names of the text fields and they are all correct....what could it be?
The problem was I did not embed the font. When I did all was well.
I've been using as3 for a lot of years but everytime I need to manipulate fonts I get crazy :(
My setup:
I'm filling up via code a movieClip with a lot of dynamic textFields. Their values come from an external XML.
My problem:
my client wants to insert html tags inside of the xml to have bold text in part of them. For example they want to have: "this string with this part bold".
The Xml part is ok, formatted with CDATA and so on. If I trace the value coming from the xml is html, but it is shown as regular text inside the textfield....
The textfields are using client custom font (not system font), and have the font embedded via embedding dialog panel in Flash by the graphic designer.
Any help?
This is the part of code that fills up the textfields (is inside a for loop)
var labelToWrite:String = labelsData.label.(#id == nameOfChildren)[VarHolder.activeLang];
if (labelToWrite != "") {
foundTextField.htmlText = labelToWrite;
// trace ("labelToWrite is -->" +labelToWrite);
}
And the trace outputs me
This should be <b>bold text with b tag</b> and this should be <strong>strong text </strong>.
Your code looks good. So the issue will be with the embedded Font. When you embed a font in flash, it doesn't embed any separate bold versions, so you may need to embed a bold version of your font.
Some resources:
Flash CS4 <b> tag in with htmlText
I find that html text works best by using the style sheets to declare your fonts instead of text formats.
var style:StyleSheet = new StyleSheet();
style.setStyle(".mainFont", { fontFamily: "Verdana", fontSize: 50, color: "#ff0000" } );
var foundTextField:TextField = new TextField();
foundTextField.embedFonts = true;
foundTextField.autoSize = TextFieldAutoSize.LEFT;
foundTextField.antiAliasType = AntiAliasType.ADVANCED;
foundTextField.styleSheet = style;
foundTextField.htmlText = "<div class=\"mainFont\">" + labelToWrite + "</div>";
See: flash as3 xml cdata bold tags rendered in htmlText with an embedded font
Other reasons maybe:
Are you embedding the right type of font (TLF vs CFF)?
If not using the flash IDE to make your textField, are you registering the font?
Font.registerFont(MyFontClass);
You can work with embeded fonts in Animate graphic design. Just add fonts and create them with a class name.
At Adobe Animate objects library you can add and create fonts as class objects like this:
Select a font and styles to add
Assign a name and export as a Action Script Class
At code frame, you must add the fonts with same classes names created before:
var gothamMediumItalic = new GothamMediumItalic();
var formatMediumItalic:TextFormat = new TextFormat();
formatMediumItalic.font = gothamMediumItalic.fontName;
var gothamBookItalic = new GothamBookItalic();
var formatBookItalic:TextFormat = new TextFormat();
formatBookItalic.font = gothamBookItalic.fontName;
var gothamBoldItalic = new GothamBoldItalic();
var formatBoldItalic:TextFormat = new TextFormat();
formatBoldItalic.font = gothamBoldItalic.fontName;
this.embedFonts = true;
this.antiAliasType = AntiAliasType.ADVANCED;
Finally, you just need to use your box added as graphic object, and set format and content:
var yourText:String = "Some Text";
boxText.defaultTextFormat = formatBook; //My default text font style
boxText.text = yourText; //Full text in same format
boxText.setTextFormat(formatBookItalic,yourText.indexOf("<i>"),yourText.indexOf("</i>")); //Some text in another format found by custom chars
That works fine and lets you use less code and more interface options. I hope this could be usefull for someone.