Solved

Actionscript 3.0 parse external text file

Posted on 2010-08-26
2
530 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 500 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

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

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

Recently, I was asked to recommend a tracking system to be implemented on a clients website. As the entire site was built on flash, my first thought was to suggest custom built tracking system. However, our company at that point of time didn't h…
The last time I worked with Flash and Socket connections was in AS1. A recent project required flash connecting to a Socket, and sending receiving information - we figured it would be easy enough - we all know about the socket policy documents and c…
In this tutorial viewers will learn how to create a basic shape tween animation in Flash including shape hints for smooth animation Open a new document in Flash: Draw a shape: Select another frame (how long you want the tween to be): Right click and…
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…

724 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