Auto-scroll Text Area

Berikut ini contoh kode untuk membuat scrollbar komponen fl.controls.TextArea otomatis bergerak ke bawah kalo ada penambahan teks sehingga baris-baris terbaru selalu kelihatan.

autoscroll

package  {
	
	import fl.controls.Button;
	import fl.controls.TextArea;
	import fl.controls.TextInput;
	import fl.events.ComponentEvent;
	import flash.display.MovieClip;
	import flash.events.Event;
	import flash.events.MouseEvent;
	

	public class Main extends MovieClip {
		
		public var console:TextArea;
		public var input:TextInput
		
		public function Main() {
			
			console.text = "A\nB\nC\nD\nE\nF\nG\nH\nI\nJ\nK\n";
			
			console.addEventListener(Event.RENDER, updateScrollPosition);

			input.addEventListener(ComponentEvent.ENTER, addText);

		}
		
		private function updateScrollPosition(e:Event):void {
			console.verticalScrollPosition = console.maxVerticalScrollPosition;
		}
		
		private function addText(e:Event):void {
			if (input.length > 0 ) {
				console.appendText(input.text + "\n");
			}
		}
		
	}
	
}

Also in this category ...