I didn't test this Exact code myself, it might not work as intended.
I did however use the TextField class! :3
Hi all you knowledge-hungry nubs!
If you didn't guess it allready, this is an ActionScript 3 tutorial. It's about the textfield class, that means you will learn how to make textfields in AS3 code!
So what is a textfield?
It's what you make with the text tool, basically.
But seriously, is there more to say here ? ._.
Maybe some questions and answers?
Q: "Couldn't you tell us where you first experienced the TextField class, Silkey?"
A: "When I was working with my current* project, I made a textfield with the text tool, but it didn't work... so good. So I did was pressed F1 and searched for dynamic text** and I found the textfield class. It worked good. :3
Q: "There isn't a lot more to ask, is there?"
A: "Nope!"
Let's just get on with it
I'm just going straight to the coding, I allready filled this topic with a lot of crap.
package stuffing { //I keep my .as files in a folder next to my .fla called stuffing.
import flash.display.MovieClip;
import flash.text.TextField;
public class TextLine extends MovieClip {
private var Text:TextField = new TextField();
public function TextLine (sentence:String) {
Text.text = sentence; //Sets the output of the Text.
Text.autosize = "center"; //This will turn the 'textbox' into a size fitting the text.
Text.selectable = false; //This is true by default, I usually don't want it selectable.
addChild(Text);
}
}
}
So that's a basic TextField for you, put it into an .as file and save it as TextLine.
Put it in your scriptfolder and then use it by doing something like this:
//Note how this code isn't complete, it felt kinda meh all that crap three times.
public class aClass {
public function aClass () {
aText = new TextLine("I ain't hungry atm, I just ate some danish pastry");
}
}
And there you go.
So what more can you do?
Oh, well you can change the font!
To do this you need to make a TextFormat, adding onto the script from before:
package stuffing {
import flash.display.MovieClip;
import flash.text.TextField;
import flash.text.TextFormat;
public class TextLine extends MovieClip {
private var Text:TextField = new TextField();
private var italicArial:TextFormat; /*A load of values going into this, if you want to skip
one just type in 'null'.
public function TextLine (sentence:String) {
/*The first value is the Font, we're gonna use Arial Narrow. You basically just put
quotations around your absolute favourite font! If you don't have one, just press the
big "T" on the toolbar to the left of you, and find one in that dropdown menu!
After that it's the size of your text. 10 is the default size.
Colour, bold, italic... go see for yourself!*/
italicArial = new TextFormat("Arial Narrow",14,0x006666,false,true);
Text.text = sentence;
Text.setTextFormat(italicArial);
addChild(Text);
}
}
}
And you're done.
I don't really know what more to put into this, for more about the TextField class, just go press F1 in the Flash CS3 closest to you!
I hope you enjoyed my tutorial, it was my first one.
*This word is extremely overused together with things like "game" and "project"
-_- I hate it, still I use it.
** Of course I got up stuff like "migrating" "constructor" and other things that don't Directly have anything to do with what I searched for.