View Full Version : slow load of external text file
sreebar
03-30-2002, 02:03 PM
Hi,
I have created a .fla that consists of 1 scene which contains a scrolling text box (with up and down buttons as well as a scrollbar) that loads an external text file. The .fla is fairly CPU intensive already, and maybe the addition of the text pushed it over the edge, but when it plays, the text takes a long time to load each time a button is hit to send the play to another part of the movie (the text box appears, but it takes up to 30 seconds to load the text depending on the computer I use), and the scrolling is hit-and-miss.
My questions are:
1) Would it be faster if I hard-coded the text right into the textbox?
2) Should I break the text up into smaller bits, and if so, HOW?
3) I would like the text to stay at the current position that is being read, regardless of what button is pressed and what frame of the movie is being played. Is there a way to do this?
I know very little about Actionscript. I followed a tutorial that I found at Actionscript.org to create the scroller, but when it comes to modifying it, I'm a little lost. So please make responses VERY SIMPLE and COMPREHENSIVE because I'm a beginner.
Thanks,
sreebar
Andy.burnett
03-31-2002, 04:05 PM
Hi Sreebar,
I don't claim any great expertise in actionscript - I am a beginner as well. However, I have been working with text in actionscript for a while and one thing I noticed is that Flash is not good at concatenating text onto an existing variable.
In other words doing this:
for (i=0; i<1000; i++){
temp += "this is my text blah blah";
}
instance.text = temp;
Is very slow. However, if you assign the lines of text to the elements of an array and then call
instance.text = myArray.join("");
It is about twice as fast.
Perhaps that might help?
sreebar
04-01-2002, 01:20 AM
Originally posted by Andy.burnett
for (i=0; i<1000; i++){
temp += "this is my text blah blah";
}
instance.text = temp;
Is very slow. However, if you assign the lines of text to the elements of an array and then call
instance.text = myArray.join("");
It is about twice as fast.
Perhaps that might help?
Andy,
The following is the script for my movie:
onClipEvent (load){
this.loadVariables("slidingtext.txt");
scrolling = 0;
frameCounter = 1;
speedFactor = 3;
numLines = 7;
resetOnNewFile = true;
origHeight = scrollbar._height;
origX = scrollbar._x;
refreshRate = 12;
refreshCounter = 0;
refreshlastMaxscroll = 0;
loaded = false;
function refreshScrollBar(){
daTextBox.scroll = resetOnNewFile ? 1 : Math.min(daTextBox.maxscroll, daTextBox.scroll);
var totalLines = numLines + daTextBox.maxscroll - 1;
scrollbar._yscale = 100*(numLines)/totalLines;
deltaHeight = origHeight - scrollbar._height;
lineHeight = deltaHeight/(daTextBox.maxScroll - 1);
scrollbar._y = lineHeight*(daTextBox.scroll - 1);
}
function updateScrollBarPos(){
scrollbar._y = lineHeight*(daTextBox.scroll - 1);
}
}
onClipEvent (enterFrame){
if( loaded ){
if(refreshCounter % refreshRate == 0 && daTextBox.maxscroll != refreshLastMaxScroll){
refreshScrollBar();
refreshLastMaxScroll = daTextBox.maxscroll;
refreshCounter = 0;
}
refreshCounter++;
}
if( frameCounter % speedFactor == 0){
if( scrolling == "up" && daTextBox.scroll > 1){
daTextBox.scroll--;
updateScrollBarPos();
}
else if( scrolling == "down" && daTextBox.scroll < daTextBox.maxscroll){
daTextBox.scroll++;
updateScrollBarPos();
}
frameCounter = 0;
}
frameCounter++;
}
onClipEvent (mouseDown){
if(up.hitTest(_root._xmouse,_root._ymouse)){
scrolling = "up";
frameCounter = speedFactor;
up.gotoAndStop(2);
}
if(down.hitTest(_root._xmouse,_root._ymouse)){
scrolling = "down";
frameCounter = speedFactor;
down.gotoAndStop(2);
}
if(scrollbar.hitTest(_root._xmouse,_root._ymouse)) {
scrollbar.startDrag(0,origX,deltaHeight,origX);
scrolling = "scrollbar";
}
updateAfterEvent();
}
onClipEvent (mouseUp){
scrolling = 0;
up.gotoAndStop(1);
down.gotoAndStop(1);
stopDrag();
updateAfterEvent();
}
onClipEvent (mouseMove){
if(scrolling == "scrollbar"){
daTextBox.scroll = Math.round((scrollbar._y)/lineHeight + 1);
}
updateAfterEvent();
}
onClipEvent (data){
loaded = true;
}
If you know, can you tell me how I would alter it to conform to what you have suggested?
Thanks,
sreebar
Andy.burnett
04-01-2002, 03:12 PM
I load my text via XML. The loadvariables approach works in a different way, so my observations about the speed of concatenating text don't apply.
The only thing I can suggest is to comment out most of your code and try to find the parts which are really slowing the application down.
sreebar
04-01-2002, 07:10 PM
Thanks, Andy
sreebar
|
vBulletin® v3.8.5, Copyright ©2000-2012, Jelsoft Enterprises Ltd.