Text File in Flash

i have a .txt file , they have with 200 lines
i want to call this file line by line in Flash Movieclip (Moves Down to upward)
each line show after the Animaction.
how can i do this ..
thanks
ISKPatelAsked:
Who is Participating?
 
BillystyxConnect With a Mentor Commented:
try this:

num = 0;
myArr = [];
val = 4;
//number of lines in txtfile
for (i=0; i<val; i++) {
      _root["var"+i] = myText.indexOf("\r\n", num);
      _root["vara"+i] = substring(myText, num, _root["var"+i]);
      myArr.push(_root["vara"+i]);
      num2 = myText.length;
      myText = substring(myText, _root["var"+i]+3, num2);
}
j = 1;
i = 0;
onEnterFrame = function () {
      if (j<myArr[i].length) {
            if (message.length<=0) {
                  message = myArr[i].substring(0, j);
            } else {
                  message = myArr[i].substring(0, j);
            }
            // message is the variable name of your textfield
            j++;
      } else {
            if(timing!=true){
                  timing=true;
            timer();
            
            }
      }
      
};
function timer(){
var intervalID;
_root.intervalID = setInterval( time, 3000 );
}
function time(){
      timing=false;
i++;
j=1;
clearInterval(_root.intervalID);

}
stop();

billystyx
0
 
BillystyxCommented:
If you want the text line by line, unless you know the specific number of character per line, I would recommend loading the text from a db.

Billystyx
0
 
BillystyxCommented:
...or if it has line break characters at the end of each line...
Billystyx
0
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
ISKPatelAuthor Commented:
but how can i load a .txt file in Flash
0
 
BillystyxCommented:
create the text file, with name value pairs, like
myVar=billystyx
and in flash, add a dynamic textfield with the variable name myVar, and add this code to the root
loadVariables("mytext.txt","","POST");


Billystyx
0
 
BillystyxCommented:
make sure the txt fiel is in the same folder as the swf (or html if ytou are viewing through html)
0
 
ISKPatelAuthor Commented:
i done this but this whole text show in the text field , but i need to show line by line after text field animation...
(Down to Upword)
0
 
BillystyxCommented:
You can load the text to a variable, and then show a number or characters at a time from line to line, but you need to know how many characters per line for this, or have some defining character at the end of each line.

That why I asked... do you know either of these things?

Billystyx
0
 
ISKPatelAuthor Commented:
ya i know each line end with "," and "."
0
 
BillystyxCommented:
with a comma and a full stop, code would look like this
frame1:
loadVariables("txtfile.txt","","POST");
frame2:
if(myText.length>0){//myText is the variable name in the txt file
      gotoAndStop(4);
}
frame3:
gotoAndPlay(3);
frame4:
num=0;
val=2;//number of lines in txtfile
for(i=0;i<val;i++){
_root["var"+i]=myText.indexOf(",.",num);
_root["vara"+i]=substring(myText,num,_root["var"+i]);
trace(_root["vara"+i]);
num=_root["var"+i]+3;

}
stop();

Billystyx
0
 
ISKPatelAuthor Commented:
Thanks Dear
but now how can i show text in Dynamic Text Field and i want this text field in Motion (Down to Upwards)
how....?
0
 
BillystyxCommented:
scrolling? Or 'typing'?

Billystyx
0
 
ISKPatelAuthor Commented:
typing
0
 
BillystyxCommented:
try this:
on frame 1 add this variable:
n=0;
make a textfield on frame4, dynamic, call it 'myText_txt'

and put this code:
if(myText_txt.length<myText.length){
myText_txt=myText_txt+substring(myText,n,1);
n++;
}
frame5:
gotoAndPlay(4);


If this doesn't work, let me know - I have a working example at home I can upload

Billystyx
0
 
BillystyxCommented:
try this:
frame1:
j=1;
frame4:
if(j < myText.length){
    message = myText.substring(0, j);//message is the variable name of your textfield
      j++;
}
frame5:
gotoAndPlay(4);

billystyx
0
 
ISKPatelAuthor Commented:
Thanks Buddy
but still my task no done
ok i give u me script those i done on it
frame1:
n=0;
loadVariables("txtfile.txt","","POST")
frame2:
if(myText.length>0)
{
gotoAndStop(3);
}
frame3:
num=0;
val=2;//number of lines in txtfile
for(i=0;i<val;i++){
_root["var"+i]=myText.indexOf(".",num);
_root["vara"+i]=substring(myText,num,_root["var"+i]);
trace(_root["vara"+i]);
gotoAndPlay(4);
num=_root["var"+i]+3;
}
stop();
frame4:// with text filed tween upto 14 frame..
if(myText_txt.length<myText.length){
myText_txt=myText_txt+substring(myText,n,1);
trace(myText_txt);
n++;
}
Frame15:
gotoAndPlay(4);

i put txt filed in Frame 4 wiht motion tween and put frame instance name is"myText_txt"

So. no out put display....

------------------------------------------
0
 
BillystyxCommented:
try my post solution above - the first was flawed.
(this one no good)

if(myText_txt.length<myText.length){
myText_txt=myText_txt+substring(myText,n,1);
n++;
}


(this one good)
frame1:
j=1;
frame4:
if(j < myText.length){
    message = myText.substring(0, j);//message is the variable name of your textfield
     j++;
}
frame5:
gotoAndPlay(4);



... and try it without the line break code from first to begin with (make a new flash doc if you need to)

The first bit can be easily incorporated into the typing method - but not directly ( I don't think anyway)

billystyx
if you need an example, just say and I will upload tonight

0
 
ISKPatelAuthor Commented:
dear
i need to show whole line
in your code they show charcter by charcter
tel is any way we put this text file line in array[]
i think we call from Array essaly
thanks...
0
 
BillystyxCommented:
frame1:
loadVariables("txtfile.txt","","POST");
frame2:
if(myText.length>0){//myText is the variable name in the txt file
     gotoAndStop(4);
}
frame3:
gotoAndPlay(3);
frame4:
//with the textfield with variable name 'message'
num = 0;
myArr = [];
val = 4;
//number of lines in txtfile
for (i=0; i<val; i++) {
      _root["var"+i] = myText.indexOf("\r\n", num);
      _root["vara"+i] = substring(myText, num, _root["var"+i]);
      myArr.push(_root["vara"+i]);
      num2 = myText.length;
      myText = substring(myText, _root["var"+i]+3, num2);
}
j = 1;
i = 0;
onEnterFrame = function () {
      if (j<myArr[i].length) {
            if (message.length<=0) {
                  message = myArr[i].substring(0, j);
            } else {
                  message = myArr[i].substring(0, j);
            }
            // message is the variable name of your textfield
            j++;
      } else {
            i++;
            j=1;
      }
};
stop();


textfile doesn't need a full stop at the end of each line - just needs a carriagle return.
This types the text from each line and then refreshes it - typing again from a clear textfield.
Hope it is what you are looking for. If you need more help - or the fla then just ask

billystyx
0
 
BillystyxCommented:
did that work? It looks good from my end - I think I might use it for something!:)

billystyx
0
 
ISKPatelAuthor Commented:
thanks dear its working like typewriter
but how can i put some delay after each next line
and can i scroll line by line ?
thanks again
0
 
BillystyxCommented:
loadVariables("txtfile.txt","","POST");
frame2:
if(myText.length>0){//myText is the variable name in the txt file
     gotoAndStop(4);
}
frame3:
gotoAndPlay(3);
frame4:
//with the textfield with variable name 'message'
num = 0;
myArr = [];
val = 4;
//number of lines in txtfile
for (i=0; i<val; i++) {
     _root["var"+i] = myText.indexOf("\r\n", num);
     _root["vara"+i] = substring(myText, num, _root["var"+i]);
     myArr.push(_root["vara"+i]);
     num2 = myText.length;
     myText = substring(myText, _root["var"+i]+3, num2);
}
j = 1;
i = 0;
onEnterFrame = function () {
     if (j<myArr[i].length) {
          if (message.length<=0) {
               message = myArr[i].substring(0, j);
          } else {
               message = myArr[i].substring(0, j);
          }
          // message is the variable name of your textfield
          j++;
     } else {
newline1=getTimer();<--these lines added
         
     }
if(newline1+2000<getTimer()){<--and here
i++;
          j=1;
}<-- to here
};
stop();


That sorts out the interval - how do you mean 'scroll line by line'?

billystyx
0
 
ISKPatelAuthor Commented:
Dear billystyx..
its mean i wanna to move my text filed Down or upward(motion tween) ...
when i complete my all work then i send u my code wiht my changes....!
can i asked ur name or lucation...?

thanks.

regards
ISKPatel
0
 
BillystyxCommented:
my email is in my profile, but to scroll the text you mean you don't want to replace each line with the next - but that you want it to go to a new line, after a space of time?

So, in essence, it would be typing itself out, one character at a time, and when it reaches the end of each line it stop and waits for a bit, and then continues. Is this correct?

Or is the original question now answered but you need to know how to scroll text in a text field?

If so, mytext.scroll +=1; on an up button
and
mytext.scroll -=1;
on a down button will scroll text.

billystyx
0
 
ISKPatelAuthor Commented:
nice profile...
and u r the expert in Macromedia Flash .....
no dear i not need a scroll bar buttons
i want to move my text box one place to other love Dwon to up ward (just we set motion tween & time line by pressing F6 button)
rest all thing working fine ... i try to set slow typing speed..
thanks

 
0
 
BillystyxCommented:
To move the texbox using motion tween you need to give the textfield an instance name, and click on character in the properties box of the textfield, click on the 2nd radio button (specify ranges), and use multiselect to choose uppercase, lowercase, numbers and punctuation.

Then, in the main timelineline, first frame again, add code like this:

myText1.onEnterFrame=function(){
this._y -=2;
}

and you will see the text box move up the screen..
if you want to stop it somewhere then:

myText1.onEnterFrame=function(){//where myText1 is the instance name you gave it
if(this._y>50){
this._y -=2;
}

billystyx
0
 
ISKPatelAuthor Commented:
Delay not working
see my code
frame4:
num = 0;
myArr = [];
val = 100;//number of lines in txtfile
for (i=0; i<val; i++) {
     _root["var"+i] = myText.indexOf("\r\n", num);
     _root["vara"+i] = substring(myText, num, _root["var"+i]);
     myArr.push(_root["vara"+i]);
     trace(myArr);
       num2 = myText.length;
     trace(num2);
        if (num2==0) {break;}
       myText = substring(myText, _root["var"+i]+3, num2);
}
j = 1;
i = 0;
onEnterFrame = function () {
      if (j<myArr[i].length) {
          if (message.length<=0) {
               message = myArr[i].substring(0, j);
                      } else {
               message = myArr[i].substring(0, j);
          }
          // message is the variable name of your textfield
         
              j++;
                 
       } else {
//delay timer..
        newline1=getTimer();
             trace(newline1);
       }
            if (newline1+25000<getTimer()){
             i++;
            j=1;       
          }
            //trace(i&j);
            //Repeat again after last line ...
            if (myArr[i].length==0){gotoAndPlay(1);}
//}
}
stop();
------------------------------------------------------
0
 
ISKPatelAuthor Commented:
Done Thanks...
0
 
BillystyxCommented:
good luck with it:)
0
 
ISKPatelAuthor Commented:
now see my almose final code
Frame1:
num = 0;
loadVariables("txtfile.txt","","POST");
Frame2:
if(myText.length>0){//myText is the variable name in the txt file
     gotoAndStop(4);
}
Frame3:
gotoAndPlay(3);
Frame4:
num = 0;
myArr = [];
val = 100;//number of lines in txtfile
for (i=0; i<val; i++) {
     _root["var"+i] = myText.indexOf("\r\n", num);
     _root["vara"+i] = substring(myText, num, _root["var"+i]);
     myArr.push(_root["vara"+i]);
     trace(myArr);
       num2 = myText.length;
     trace(num2);
        if (num2==0) {break;}
       myText = substring(myText, _root["var"+i]+3, num2);
}
j = 1;
i = 0;
onEnterFrame = function () {
      if (j<myArr[i].length) {
          if (message.length<=0) {
               message = myArr[i].substring(0, j);
                      } else {
               message = myArr[i].substring(0, j);
          }
          // message is the variable name of your textfield
         
              j++;
                 
       } else {
        //time delay after each line
            if(timing!=true){
               timing=true;
          timer();
         
          }
     }
 };
function timer(){
var intervalID;
_root.intervalID = setInterval(time, 2000 );
}
function time(){
     timing=false;
i++;
j=1;
 clearInterval(_root.intervalID);
 if (myArr[i].length==0){gotoAndPlay(1);}
}
stop();
-------------------------------------------------------------
Thanks again to help me ...

0
 
BillystyxCommented:
no worries - is there anything else with this code you need help with? Or is that it?

billystyx
0
 
BillystyxCommented:
Hello, are you finished here in terms of the original question, or is there something else?

Billystyx
0
All Courses

From novice to tech pro — start learning today.