-
AS3 Increasing the length of a string
I am working on the following code and I keep getting a cut off at around the 'C' of Dave's computer.
I know this is going to be a simple answer but I for the life of me cannot figure out HOW to extend the string visual field. I am pretty sure the secret lies in the variable len.
Any help would be great.
Code:
import flash.text.TextField;
import flash.events.Event;
var txtFld:TextField = new TextField();
addChild(txtFld);
txtFld.textColor = 0xFF0000;
var str:String = "Hello, I am Dave's Computer. Even I can tell that TingTing is the most wonderful woman ever.";
var len:int = str.length;
var i:int = 0;
this.addEventListener (Event.ENTER_FRAME, onEnter, false, 0,true);
function onEnter(evt:Event):void {
txtFld.appendText (str.charAt (i));
i++;
if (i > len) {
removeEventListener(Event.ENTER_FRAME, onEnter);
}
}
-
Total Universe Mod
Set the autoSize property.
Code:
import flash.text.TextField;
import flash.events.Event;
var txtFld:TextField = new TextField();
txtFld.autoSize = TextFieldAutoSize.LEFT;
addChild(txtFld);
txtFld.textColor = 0xFF0000;
var str:String = "Hello, I am Dave's Computer. Even I can tell that TingTing is the most wonderful woman ever.";
var len:int = str.length;
var i:int = 0;
this.addEventListener (Event.ENTER_FRAME, onEnter, false, 0,true);
function onEnter(evt:Event):void {
txtFld.appendText (str.charAt (i));
i++;
if (i > len) {
removeEventListener(Event.ENTER_FRAME, onEnter);
}
}
-
a little trick that i often use instead of autosize is
tf.width = tf.textWidth + 10;
tf.height = tf.textHeight + 10;
* make sure that you do this after filling the text in the field
-
Thank you both for your help!
While we are on the subject, I am very curious now on how to start a new line.
So instead of having a sentence like this.
You
Could
Do
Something
Like
This.
Or even have a sentence,
like this.
-
when adding text? you could setup htmlText and use <br> or you could just use \n in the text
-
Ah so it's like JavaScript in that aspect.
Learn something new every day.
Thanks much!
-
if you are familiar with JS you will find a lot of similarities with actioscript
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|