Solved

Actionscript 3.0 parse external text file

Posted on 2010-08-26
2
523 Views
Last Modified: 2013-11-11
I have a function that reads an external text file, and I have it able to display the file.  But I want to be able to display the contents of the text file ONE LINE at a time, with a delay between each line.. and during that delay, I want to be able to turn on an object and turn it off when the delay is done...

The following code does pretty much what I want, but the problem is it will stop on X number of characters, I want it to be able to stop on a word.. so that the entire word is displayed.

Any help would be appreciated.

-Joe
var url:String = texturl;

var t:int = 0;

var iMult:int = 1;

var timer:Timer = new Timer(2000);

var i:uint = 0;

var iLines:uint = 35;

var myLoader:URLLoader = new URLLoader();



myLoader.addEventListener(Event.COMPLETE, completeHandler);

myLoader.load(new URLRequest(url));



timer.start();

timer.addEventListener(TimerEvent.TIMER, gotime);

	

function gotime(e:TimerEvent)

{

	trace("Timer Event Called");

	while (t < (iLines * iMult))

	{

		trace("While Loop started");

		textbox_txt.appendText(str.charAt(t));

		t++;

		if(t>=str.length)

		{

			timer.stop();

		}

	}

	iMult++;

}

Open in new window

0
Comment
Question by:adworldmedia
2 Comments
 
LVL 10

Expert Comment

by:Carnou
Comment Utility
I'd make use of the string.split() function.  If you want line at a time, it's simple (warning, untested code):
var arr:Array = str.split( "\n" );
for each (var s:String in arr)
{
    textbox_txt.appendText(s);
    textbox_txt.verticalScrollPosition = textbox_txt.maxVerticalScrollPosition; // this will make the scroll area follow your entry
}
I may have oversimplified, but that should be the general idea.  If you want word by word, change the split command to be str.split( " " );
Hope this helps!
0
 
LVL 1

Accepted Solution

by:
Adveho earned 500 total points
Comment Utility

Now I didn't test this, but I think it's about right...
Atleast the general idea is. :)

Hope it helps. Good luck.

/*** Code start **/

var url:String = texturl;
var t:int = 0;
var iMult:int = 1;
var timer:Timer = new Timer(2000);
var i:uint = 0;
var iLines:uint = 35;
var myLoader:URLLoader = new URLLoader();
var arr:Array;

myLoader.addEventListener(Event.COMPLETE, completeHandler);
myLoader.load(new URLRequest(url));

/* This is missing? */
completeHandler(e:Event):void {
 // don't want the timer to start till the file is completely loaded.
 arr = e.currentTarget.split('\n');
  timer.start();
  timer.addEventListener(TimerEvent.TIMER, gotime);
}

      
function gotime(e:TimerEvent)
{
for(var i:int = 0; i < arr.length; ++i){
  if(i == iMult) {
 textbox_txt.appendText(arr[i]);      
 }
}
if(iMult == arr.length){
timer.stop();
}
      iMult++;
}
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Suggested Solutions

Here are some practices and techniques that can be adopted into your Flash/Flex application development process. Note: Not all "performance tips" provide an immediately-recognizable benefit.   This article does not include timing validation data,…
I have been doing hardcore actionscripting for some time; and needless to say I have faced a lot of problems in just understanding others' code rather than understanding what the code executes. A programmer's life can become hell when there are a lo…
In this tutorial viewers will learn how to create a basic motion tween animation in Flash Open a new document in Flash: Draw/import an image: Press CTRL + F8 to convert it into a graphic symbol: Select a frame (how long you want the tween to last): …
The goal of the tutorial is to teach the user how to live broadcast using Flash Media Live Encoder and connecting it to YouTube to broadcast. Log into your Youtube account, choose live stream settings, start live stream from Flash Media Live Enc…

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now