?
Solved

Actionscript 3.0 parse external text file

Posted on 2010-08-26
2
Medium Priority
?
532 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 10

Expert Comment

by:Carnou
ID: 33536632
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 2000 total points
ID: 33741781

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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I come across a lot of question about how to access things in the document class from a movieclip, or accessing something from a movieclip in the document class. It took me a while to figure this out but once I did it makes life so much easier. …
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 use the auto adjust feature and what the different options do. When your video is not working right you can choose the auto adjust feature to help choose your settings.
Suggested Courses
Course of the Month13 days, 14 hours left to enroll

801 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