Flash / Flex / ActionScript/TextField/Scroll — различия между версиями
Admin (обсуждение | вклад) м (1 версия) |
|
(нет различий)
|
Версия 09:19, 26 мая 2010
Содержание
Responding to Scroll Events
package {
import flash.display.Sprite;
import flash.text.TextField;
import flash.events.Event;
public class Main extends Sprite {
public function Main( ) {
var field:TextField = new TextField( );
field.autoSize = flash.text.TextFieldAutoSize.LEFT;
field.text = "AAA BBB CCC DDD AAA BBB CCC DDD AAA BBB CCC DDD AAA BBB CCC DDD";
field.addEventListener(Event.SCROLL, onTextScroll);
addChild(field);
}
private function onTextScroll(event:Event):void {
trace("scroll");
}
}
}
Scrolling Text Programmatically
package {
import flash.display.Sprite;
import flash.text.TextField;
public class Main extends Sprite {
public function Main( ) {
var field:TextField = new TextField( );
field.scrollV = 1; // Scroll to the top
field.scrollV += 1; // Scroll to the next line
field.scrollV = 6; // Scroll to line 6
field.autoSize = flash.text.TextFieldAutoSize.LEFT;
field.wordWrap = true;
field.text = "AAA BBB CCC DDD AAA BBB CCC DDD AAA BBB CCC DDD AAA BBB CCC DDD";
addChild(field);
}
}
}
Set horizontal scroll value
package {
import flash.display.Sprite;
import flash.text.TextField;
public class Main extends Sprite {
public function Main( ) {
var field:TextField = new TextField( );
field.scrollH = 0; // Scroll to the far left
field.scrollH += 1; // Scroll to the right 1 pixel
field.scrollH = field.maxScrollH; // Scroll to the far right
field.autoSize = flash.text.TextFieldAutoSize.LEFT;
field.wordWrap = true;
field.text = "AAA BBB CCC DDD AAA BBB CCC DDD AAA BBB CCC DDD AAA BBB CCC DDD";
addChild(field);
}
}
}
package {
import flash.display.Sprite;
import flash.text.TextField;
public class Main extends Sprite {
public function Main( ) {
var field:TextField = new TextField( );
field.scrollV = field.bottomScrollV;
field.scrollV = field.bottomScrollV + 1;
field.autoSize = flash.text.TextFieldAutoSize.LEFT;
field.wordWrap = true;
field.text = "AAA BBB CCC DDD AAA BBB CCC DDD AAA BBB CCC DDD AAA BBB CCC DDD";
addChild(field);
}
}
}
Using the Scroll Properties
package
{
import flash.text.TextField;
import flash.events.MouseEvent;
import flash.display.Sprite;
public class Main extends Sprite
{
private var txt:TextField;
public function Main()
{
txt = new TextField();
txt.multiline = true;
txt.wordWrap = true;
txt.text = "Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text ";
txt.height = 100
txt.width = 50;
addChild(txt);
txt.addEventListener(MouseEvent.MOUSE_MOVE, scrollTextField);
}
private function scrollTextField(mouseEvent:MouseEvent):void
{
if (mouseEvent.stageY < 30)
{
txt.scrollV--;
}
if (mouseEvent.stageY > 70)
{
txt.scrollV++;
}
}
}
}