13.08.2012 Views

ACTIONSCRIPT 3 Developer’s Guide en

ACTIONSCRIPT 3 Developer’s Guide en

ACTIONSCRIPT 3 Developer’s Guide en

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

<strong>ACTIONSCRIPT</strong> 3.0 DEVELOPER’S GUIDE<br />

Using the TextField class<br />

Scrolling text in a text field<br />

Flash Player 9 and later, Adobe AIR 1.0 and later<br />

In many cases, your text can be longer than the text field displaying the text. Or you may have an input field that allows<br />

a user to input more text than can be displayed at one time. You can use the scroll-related properties of the<br />

flash.text.TextField class to manage l<strong>en</strong>gthy cont<strong>en</strong>t, either vertically or horizontally.<br />

The scroll-related properties include TextField.scrollV, TextField.scrollH and maxScrollV and maxScrollH.<br />

Use these properties to respond to ev<strong>en</strong>ts, like a mouse click or a keypress.<br />

The following example creates a text field that is a set size and contains more text than the field can display at one time.<br />

As the user clicks the text field, the text scrolls vertically.<br />

package<br />

{<br />

import flash.display.Sprite;<br />

import flash.text.*;<br />

import flash.ev<strong>en</strong>ts.MouseEv<strong>en</strong>t;<br />

public class TextScrollExample ext<strong>en</strong>ds Sprite<br />

{<br />

private var myTextBox:TextField = new TextField();<br />

private var myText:String = "Hello world and welcome to the show. It's really nice to<br />

meet you. Take your coat off and stay a while. OK, show is over. Hope you had fun. You can go<br />

home now. Don't forget to tip your waiter. There are mints in the bowl by the door. Thank you.<br />

Please come again.";<br />

}<br />

}<br />

public function TextScrollExample()<br />

{<br />

myTextBox.text = myText;<br />

myTextBox.width = 200;<br />

myTextBox.height = 50;<br />

myTextBox.multiline = true;<br />

myTextBox.wordWrap = true;<br />

myTextBox.background = true;<br />

myTextBox.border = true;<br />

}<br />

var format:TextFormat = new TextFormat();<br />

format.font = "Verdana";<br />

format.color = 0xFF0000;<br />

format.size = 10;<br />

myTextBox.defaultTextFormat = format;<br />

addChild(myTextBox);<br />

myTextBox.addEv<strong>en</strong>tList<strong>en</strong>er(MouseEv<strong>en</strong>t.MOUSE_DOWN, mouseDownScroll);<br />

public function mouseDownScroll(ev<strong>en</strong>t:MouseEv<strong>en</strong>t):void<br />

{<br />

myTextBox.scrollV++;<br />

}<br />

Last updated 6/6/2012<br />

376

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!