00:00
00:00
Newgrounds Background Image Theme

DegasTyson54 just joined the crew!

We need you on the team, too.

Support Newgrounds and get tons of perks for just $2.99!

Create a Free Account and then..

Become a Supporter!

As3: TextField class

6,529 Views | 4 Replies
New Topic Respond to this Topic

As3: TextField class 2007-09-09 11:10:24


As3: Main

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.

Response to As3: TextField class 2007-09-14 14:19:12


that's pretty good for starters
i made an exact class like this only for AS2
i really should start getting into AS3 OOP...

nice, simple tut


BBS Signature

Response to As3: TextField class 2007-09-14 14:57:45


Nice tut and class Silkey. I'm surprised this hasn't gotten more replies. I haven't done much OOP with AS3, I have with AS2 I was working on something like this too.I like the way this was written, it made it less boring, which it really needed to be, a textfield tutorial isn't as interesting as say...a platformer tutorial, and it's especially so for beginners. And it reminds me, I promised myself to write some AS3 tutorial. The problem is, I can't think of many differences between this and AS2 that haven't been covered. All I can think of is tutorials on game development and OOP...meh I'm rambling.

Response to As3: TextField class 2007-09-22 06:13:16


Maybe you could make a tutorial about some of these.. more uninteresting classes, like the TextField one!

Response to As3: TextField class 2007-09-22 15:31:29


very nice tut


cba to make a sig....