Thursday, April 16, 2009

TextField - Flash CS4 Professional ActionScript 3.0 Language Reference

TextField - Flash CS4 Professional ActionScript 3.0 Language Reference

The following example defines two TextField objects. The first TextField object has two associated event handlers. When you click the mouse inside this first text field, the mouseDown event is dispatched, and the associated mouseDownScroll handler is called. The mouseDownScroll() handler causes the field to scroll. Then, the scroll event is dispatched, and the associated scrollHandler() handler updates the second text field to display the current scroll position.

package
{
import flash.display.Sprite;
import flash.text.*;
import flash.events.Event;
import flash.events.TextEvent;
import flash.events.MouseEvent;
public class TextScrollExample extends Sprite
{
private var myTextBox1:TextField = new TextField();
private var myTextBox2:TextField = new TextField();
private var myText:String = "Hello world and welcome to the show. It's really nice to meet you. Take your coat off and stay a while. OK, show is over. Hope you had fun. You can go home now. Don't forget to tip your waiter. There are mints in the bowl by the door. Thank you. Please come again.";
public function TextScrollExample()
{
myTextBox1.text = myText;
myTextBox1.width = 200;
myTextBox1.height = 50;
myTextBox1.multiline = true;
myTextBox1.wordWrap = true;
myTextBox1.background = true;
myTextBox1.border = true;

myTextBox2.x=220;
myTextBox2.text="scrolled to line: " + myTextBox1.scrollV;
addChild(myTextBox1);
addChild(myTextBox2);
myTextBox1.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownScroll);
myTextBox1.addEventListener(Event.SCROLL, scrollHandler);
}
public function mouseDownScroll(event:MouseEvent):void
{
myTextBox1.scrollV++;
}
public function scrollHandler(event:Event):void
{
myTextBox2.text="scrolled to line: " + myTextBox1.scrollV;
}
}
}

No comments:

Post a Comment