Forum Topic: As3: TextField class

(1,104 views • 4 replies)

This topic is 1 page long.

<< < > >>
None

Silkey

Reply To Post Reply & Quote

Posted at: 9/9/07 11:10 AM

Silkey NEUTRAL LEVEL 10

Sign-Up: 07/23/06

Posts: 148

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.


None

medhopz

Reply To Post Reply & Quote

Posted at: 9/14/07 02:19 PM

medhopz EVIL LEVEL 13

Sign-Up: 04/09/06

Posts: 178

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

None

Pedochu

Reply To Post Reply & Quote

Posted at: 9/14/07 02:57 PM

Pedochu FAB LEVEL 02

Sign-Up: 05/15/07

Posts: 655

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.


None

Silkey

Reply To Post Reply & Quote

Posted at: 9/22/07 06:13 AM

Silkey NEUTRAL LEVEL 10

Sign-Up: 07/23/06

Posts: 148

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


Happy

super-gerbil

Reply To Post Reply & Quote

Posted at: 9/22/07 03:31 PM

super-gerbil LIGHT LEVEL 09

Sign-Up: 07/26/07

Posts: 21

very nice tut

cba to make a sig....


All times are Eastern Standard Time (GMT -5) | Current Time: 08:59 AM

<< Back

This topic is 1 page long.

<< < > >>
You need a Grounds Gold Account to post on the NG BBS! If you don't have one, click here to sign up now! It's fast, free, and easy — and opens up tons of great NG features!