Flash TextArea Component ActionScript 3 Tutorial
This Flash Component tutorial series show how to use TextAreal with Flash ActionScript 3.
Flash Tutorial Content:
The Flash TextArea component is a multiline text field with a border and optional scroll bars. The TextArea component supports the HTML rendering capabilities of Adobe Flash Player.
The finished Flash Movie of this tutorial is shown as above. Click on the above Flash Movie and play around.
Flash ActionScript Codes:
//Create a new loader to load the text file
var myURLLoader = new URLLoader();
//Specify the data format
myURLLoader.dataFormat = URLLoaderDataFormat.TEXT;
//Load the text file (story.txt)
myURLLoader.load(new URLRequest("story.txt"));
//Set the Text Format of the TextArea (story_ta)
var textAreaFormat:TextFormat = new TextFormat("Arial", 14, 0x3333FF);
story_ta.setStyle("textFormat", textAreaFormat);
//Listen to when the loading COMPLETE
myURLLoader.addEventListener(Event.COMPLETE, loadTextFile);
function loadTextFile(evt:Event) {
//story_ta.wordWrap = true;
//Load the text file to TextArea
//replace double empty line with a single empty line
story_ta.text = evt.target.data.replace(/\r/g,"");
}
// Allow Text Fields to input data
inputText_txt.type = TextFieldType.INPUT;
//Allow wordWrap
inputText_txt.wordWrap = true;
//Set the New Paragraph RadioButton to be selected by default
newParagraph_rb.selected = true;
//Declare the Radio group (belong to same group)
//This can be done by using the first RadioButton (newParagraph_rb)
var textRadioGroup:Object = newParagraph_rb.group;
//Add event listener to the Enter button
enter_btn.addEventListener(MouseEvent.CLICK, appendText);
function appendText(evt:MouseEvent):void {
if (inputText_txt.text == "") {
story_ta.appendText("\n\n"+ inputText_txt.text);
story_ta.appendText(" "+ inputText_txt.text);
story_ta.verticalScrollPosition = story_ta.maxVerticalScrollPosition;
//Clear inputText_txt
inputText_txt.text = "";
}
Download Flash Source File:
Remarks:
This Flash ActionScript tutorial shows how to use Flash TextArea component.