Actionscript 3 Text below image in TextArea.htmlText - actionscript-3

I would like to display an image and a text below it in a TextArea but I can't figure out why the text is displayed on the right of the image.
Here is my code :
var textArea:TextArea = new TextArea();
var urlLdr:URLLoader = new URLLoader();
urlLdr.addEventListener(Event.COMPLETE, completeHandler);
urlLdr.dataFormat = URLLoaderDataFormat.TEXT;
urlLdr.load(new URLRequest("myText.html"));//the file only contains the string "Test image" with no html tag
function completeHandler(event:Event):void {
var str:String = event.target.data as String;
htmlTextArea.htmlText = "<p><img src='myImage.jpg'/> </p>";
htmlTextArea.htmlText += "<p>"+str+"</p>";
addChild(htmlTextArea);
}
And I get :
I tried by adding the tag < br/ > , and \n in the htmlText between the image and the text but it only makes the text be written lower on the right.
With :
htmlTextArea.htmlText = "<p><img src='myImage.jpg'/> </p><br/><br/><br/>";
I get :
So, how to write the text below the image?

Related

How do I format different lines of text differently, from a textfield created in AS3, with text populated from a txt file?

So I have a flash file in AS3, latest version of flash.
It creates a text box in AS3. It then uses AS3 to grab text from a text file (2 lines) and loads it in. I then used further code to format the text size, font, color etc.
But NOW...I need line 1 of the text box to be a certain format (large, caps) and the second line to be a different format (smaller, no caps)
Here is all my code below:
//BEGIN TXT LOADER
var myTextLoader:URLLoader = new URLLoader();
var winnerText:TextField = new TextField();
myTextLoader.addEventListener(Event.COMPLETE, onLoaded);
function onLoaded(e:Event):void {
winnerText.text = e.target.data;
addChild(winnerText);
}
myTextLoader.load(new URLRequest("EditableText.txt"));
//BEGIN TEXT BOX FORMATTING
winnerText.width = 1920;
winnerText.height = 300;
winnerText.y = 430;
//BEGIN TEXT & FONT FORMATTING
var casinoBranding:TextFormat = new TextFormat();
casinoBranding.size = 90;
casinoBranding.align = TextFormatAlign.CENTER;
casinoBranding.font = "Bliss Pro";
casinoBranding.leading = -50;
winnerText.defaultTextFormat = casinoBranding;
You can apply a TextFormat like #Aaron suggests. Another way of doing is to use stylesheets. Here is an example
http://snipplr.com/view/39474/as3-textfield-and-stylesheet-example-created-in-actionscript/
You can apply a TextFormat to a specific range of text using TextField/setTextFormat().
To apply a different text format to the first line of text you can do this:
var casinoBranding:TextFormat = new TextFormat();
var casinoBrandingFirstLine:TextFormat = new TextFormat();
// ... apply formatting options
function onLoaded(e:Event):void {
winnerText.defaultTextFormat = casinoBranding;
winnerText.text = e.target.data;
winnerText.setTextFormat(casinoBrandingFirstLine, 0, winnerText.getLineOffset(1));
}
Note that if word wrapping is involved it changes what the "first line" really means.

AS3 - Add scroll bar to dynamically generated text field?

I'm new to actionscript 3, so please forgive me.
I am loading a text file into my flash file and then dynamically creating a text field which will take in the myBody text from that file. The problem is that the text in myBody could be very long, so I would like to add a scroll bar when needed to the dynamically generated text field. Is there any way to this?
var myTextLoader:URLLoader = new URLLoader();
myTextLoader.dataFormat=URLLoaderDataFormat.VARIABLES;
var myTextField_txt:TextField = new TextField();
myTextField_txt.multiline = true;
myTextField_txt.wordWrap = true;
myTextField_txt.border = true;
myTextField_txt.height = 100;
myTextLoader.addEventListener(Event.COMPLETE, onLoaded);
function onLoaded(e:Event):void {
myTextField_txt.text = e.target.data.myBody;
addChild(myTextField_txt);
}
myTextLoader.load(new URLRequest("mySampleFile.txt"));

How to highlight static text background in AS3 dynamically?

If i can search a word in search box that word will find static text then highlight appear in flash as3. Any suggest please?
You can use .getCharBoundaries(), which returns a Rectangle encompassing a character at a given index in your TextField.
Using that Rectangle, you can create some highlight graphics. Here's a function that will simplify that process:
function highlightChar(textField:TextField, charIndex:int):void
{
var rect:Rectangle = textField.getCharBoundaries(charIndex);
var box:Shape = new Shape();
box.blendMode = BlendMode.MULTIPLY;
box.graphics.beginFill(0xFFCC33);
box.graphics.drawRect(textField.x + rect.x, textField.y + rect.y, rect.width, rect.height);
box.graphics.endFill();
if(textField.parent) textField.parent.addChild(box);
}
From here, you can create another function that will accept a phrase to highlight:
function highlightPhrase(textField:TextField, phrase:String):void
{
var start:int = textField.text.indexOf(phrase);
if(start >= 0)
{
for(var i:int = start; i < phrase.length; i++)
{
highlightChar(textField, i);
}
}
}
Combined, you'll find it easily to highlight a block of text like this:
var t:TextField = new TextField();
t.text = "This text is highlighted";
addChild(t);
highlightPhrase(t, "This text");

AS3 TLF text bolding as html

I am having a problem with TLF text in flash.
So I'm reading a .csv file. In it I have "Some text<br><b>some bold text</b><br>bla bla"
I read this in and output it to a textbox that is set to standard Arial.
The <br> tags work fine but the <b> tags do NOT... Any suggestions?
function loadText(fileToLoad:String):void
{
csvLoader = new URLLoader();
csvLoader.dataFormat = URLLoaderDataFormat.TEXT;
csvLoader.load(new URLRequest("TextFiles/" + fileToLoad + ".csv"));
csvLoader.addEventListener(Event.COMPLETE,CSVLoaded);
}
function CSVLoaded(e:Event):void
{
var str:String = csvLoader.data as String;
var arr:Array = str.split("\n");
for (var i:int=0; i<arr.length; i++)
{
arr[i] = arr[i].split(';');
}
ExtraInfo.Heading.htmlText = arr[0][0];
ExtraInfo.MainText.htmlText = arr[0][1];
}
I tried with just <b></b> tags... didn't work for me either.
Then it turns out to be Font embedding issue.
Since you are using Arial, you can set the anti-alias property of the TLF textfield to use device fonts.
But it's always better to embed the fonts...

save text of textarea and reuse it to replace text in textarea

Is it possible to save text of textarea (flash 10, as3, cs5) in some variable or so and with its textformat (more than one color) and then reuse it to replace text in textarea?
I tried saving htmlText of textarea but the problem is when i replace it in textarea tags causes problem. There will always be another extra line.
If anyone wants to view p tags problem try following. Just click on text and then move your down arrow key, cursor will go to next line.
import fl.controls.TextArea;
var txtHTML:TextArea = new TextArea();
txtHTML.move(0,0);
var default_format:TextFormat = new TextFormat();
default_format.font = "Arial";
default_format.bold = false;
default_format.align = "center";
default_format.color = 0xFFFF00;
default_format.size = 14;
var field:TextField = txtHTML.textField;
field.defaultTextFormat = default_format;
field.setTextFormat(default_format);
field.alwaysShowSelection = true;
field.background = true;
field.type = 'input';
field.multiline = true;
field.backgroundColor = 0x777777;
field.embedFonts = true;
txtHTML.htmlText = '<P ALIGN="CENTER"><FONT FACE="_sans" SIZE="14" COLOR="#FFFF00" LETTERSPACING="0" KERNING="0">ASDF</FONT></P>';
field.x = 0;
field.y = 0;
field.width = 400;
field.height = 200;
field.text = "";
addChild(txtHTML);
Is there a way to do this?
Just copy the text and remove the last character i.e. '>'. So there won't be <p></p> tags problem of extra line.
Regards