00:00
00:00
Newgrounds Background Image Theme

markololohands 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!

AS: advanced text formatting

1,760 Views | 2 Replies
New Topic Respond to this Topic

AS: advanced text formatting 2007-04-14 17:19:42


AS: main

better than a hernia

intro

there are not onlt dynamic text boxes but input aswell,in this tutorial you will learn text formating,and other useful tidbits of script for textfields! :D

my first tutorial,bare with me :/

to start off

first create a text field,we will call it “tex�
to do this we use a function called createTextField
so we would do

createTextField(“instance name�,depth,x position,y position,width,height)

createTextField("tex",1,50,50,200,50)

that starts us off with a base for our text

now to give out text a value we would do something like this

tex.text= “I am a text field�

so al together we have

createTextField("tex",1,50,50,200,50)
tex.text= “I am a text field�

now,all that is, is some plain old text right??
Want some color?

I would,so add this

tex.textColor=0xff0000

that sets out text variable’s color to red,using a hexidecimal
so we will leave it at that for now

createTextField("tex",1,50,50,200,50)
tex.text= "I am a text field"
tex.textColor=0xff0000

now lets get into the good stuff,we must set a variable to allow text formatting

font,style,size,etc…

so we would add this

var tformat:TextFormat = new TextFormat()

which is our base,now lets say we want our text to be a font like Courier New.
so then you would put

tformat.font=� Courier New�

test your movie
see nothing happens,that’s because you need to add that formatting variable to your textfield
like this,

tex.setTextFormat(tformat)

so our code is now

createTextField("tex",1,50,50,200,50)
tex.text= "I am a text field"
tex.textColor=0xff0000
var tformat:TextFormat = new TextFormat()
tformat.font="Courier New"
tex.setTextFormat(tformat)

now for some effects,like bold ,or ittalic
add
tformat.bold=true
or
tformat.italic=true

at default they are false,so play around abit

want bigger text?
Use .size
Still in the format variable we would add something like
tformat.size=15

our code so far

createTextField("tex",1,50,50,200,50)
tex.text= "I am a text field"
tex.textColor=0xff0000
var tformat:TextFormat = new TextFormat()
tformat.font="Courier New"
tformat.bold=true
tformat.size=15
tex.setTextFormat(tformat)
now lets say we wanted to make it an iput text field,for a game maby,then you would do this

tex.type="input"

not our formating variable,tex,which is our actual instance name

so our final code is

createTextField("tex",1,50,50,200,50)
tex.text= "I am a text field"
tex.textColor=0xff0000
tex.type="input"
var tformat:TextFormat = new TextFormat()
tformat.font="Courier New"
tformat.bold=true
tformat.size=15
tex.setTextFormat(tformat)

now,that’s some nice text!

But some other useful functions are:

One of my favorites here!

Restrict

This function allows you to restrict text to only selected numbers/letters

So lets say you wanted a users input to be numbers from 1-5
So use:
tex.restrict="12345"

our code is now

createTextField("tex",1,50,50,200,50)
tex.text= "I am a text field"
tex.textColor=0xff0000
tex.type="input"
tex.restrict="12345"
var tformat:TextFormat = new TextFormat()
tformat.font="Courier New"
tformat.bold=true
tformat.size=15
tex.setTextFormat(tformat)

now what if you don’t want numbers and you only want letters?
EASY!!

tex.restrict="a-z A-Z"
that allows capitals and lowercase

Want more options,well todays your lucky day because there is a lot more!

Here are some parts of text that can be changed

Defaults:

autoSize="none"
border= false
borderColor= 0x000000
background=false
backgroundColor= 0xffffff
condenseWhite=false
gridFitType="pixel"
html= false
maxChars="null"
password=false
restrict = null
selectable=true
textColor=0x000000
thickness=0
type = "dynamic"
multiline= false

happy coding!

and thanks for reading

Grah i feel so unknown, SK8MORE god damn :/ EvanHayes seems like a much more serious name than sk8more,so i changed it.

Response to AS: advanced text formatting 2007-04-14 17:27:28


damn you bbs,screwing up my " s
soory guys,if you cant read it,ill repost


Grah i feel so unknown, SK8MORE god damn :/ EvanHayes seems like a much more serious name than sk8more,so i changed it.

Response to AS: advanced text formatting 2007-04-15 11:13:01


Sweet thanks for the help. Great info.