Flash CS4 - Scrollable Text Area with External Text - Ari Efendi

Advertisement

ads

Hot

Post Top Ad

Your Ad Spot

Saturday, January 1, 2011

Flash CS4 - Scrollable Text Area with External Text

First, create a folder on your computer to store the files for this tutorial. In that folder, create a text file called external.txt and fill it with text (I use lipsum.com to generate a bunch of dummy text).

In Flash, create a new movie, choose Flash File (Actionscript 3.0).

Use the Text Tool (T) and drag out a textarea on your stage. In the Properties (Ctrl + F3), give the textarea an Instance Name of scrolltext, choose Dynamic Text below that and make sure Behavior (under Paragraph) is set to Multiline.

Double-click the textarea (where it's editable), open the Components window (Ctrl + F7) and drag an instance of the UIScrollBar into the textarea. It should snap it to the right side of the textarea.

Save (Ctrl + S), but don't close, your flash file to the same folder as the text file you created. Now right-click the first frame of your Timeline and choose Actions.

Add the following code:

var file:String = "external.txt";
var loader:URLLoader=new URLLoader(new URLRequest(file));

loader.addEventListener(Event.COMPLETE, isComplete);

function isComplete(event:Event):void {
    var loadedtext:URLLoader = URLLoader(event.target);
    scrolltext.text = loadedtext.data;
}


The first line simply defines our file.

The second line uses URLLoader and URLRequest. URLRequest captures the information from the file. The URLLoader will load the data from that file into your movie. Note that all of the data will be downloaded before it is accessible.

The next line adds an Event Listener to listen for when the entire file is loaded (COMPLETE). When it recognizes that the file is loaded, it calls a function (isComplete in this case) which determines what will be done with the data.

Finally, the isComplete function handles the data after it is loaded into the movie, assigning it to our scrolltext textarea.



 

Demikianlah artikel singkat ini dibuat semoga bermanfaat, jika ada kesalahan pada ide dan penulisan saya mohon maaf.

No comments:

Post a Comment

Post Top Ad

Your Ad Spot