17 Replies Latest reply on Mar 12, 2010 10:57 AM by kglad

    Text File Controlling Movie Timeline

    thereiter

      I have a movie where on the main timeline stage I have placed a movie clip (Clip1) and a dynamic text field. I have a .txt document that contains a variable that will always be a number (Var1).

       

      Currently, the dynamic text field reads Var1 and displays that number. This is great, but I want Var1 to be used in 2 places:

       

      How can I get Clip1 to also read Var1 and, based on the number that is Var1, play a certain frame of Clip1?

       

      I'd like it to go like this:

      If Var1 is <1000 then play frame1, If Var1 is =1000 and <2000 then play frame2, If Var1 is =2000 and <3000 then play frame3, and so on...

       

      Any help will be greatly appreciated. I am using ActionScript 1.

       

      Thanks.

        • 1. Re: Text File Controlling Movie Timeline
          kglad Adobe Community Professional & MVP

          in your onLoad() or onData() method, use:

           

          Clip1.gotoAndPlay(1+Math.floor(Var1/1000));

          1 person found this helpful
          • 2. Re: Text File Controlling Movie Timeline
            thereiter Level 1

            Kglad, Here is my code as of now. I have 24 frames and each frame should be played upon a specific value range (like between 0 and 999). How should I write that?

             

            Thanks so much!

             

            CODE

             

            loadVariablesNum("http://www.Myserver.com/Var1.txt",0);

            • 3. Re: Text File Controlling Movie Timeline
              thereiter Level 1

              Should Clip1 in the code suggested be the Movie Clip name or the Instance Name? Instance Name, correct? Thanks again.

              • 4. Re: Text File Controlling Movie Timeline
                kglad Adobe Community Professional & MVP

                use loadvars.  otherwise, you have to setup a loop to check with your variable is defined.  and post the text in Var1.txt.

                • 5. Re: Text File Controlling Movie Timeline
                  thereiter Level 1

                  Here is what I've written, but it doesn't play the right frame:

                   

                  loadVariablesNum("http://www.myserver.com/mytext.txt",0);
                  "mytext.txt".onLoad(Clip1.gotoAndPlay(1+Math.floor(Var1/500)));

                  • 6. Re: Text File Controlling Movie Timeline
                    thereiter Level 1

                    Hmm... I've used the code as in Post #5 above, but changed to

                    loadVariables instead of loadVariablesNum - still no luck... Thoughts?

                    • 7. Re: Text File Controlling Movie Timeline
                      kglad Adobe Community Professional & MVP

                      post the text in Var1.txt.

                      • 8. Re: Text File Controlling Movie Timeline
                        thereiter Level 1

                        Okay. I've renamed my clip, txt and dynamic text field. See the text below and the code. Thanks.

                         

                        Txt doc="runr.txt"

                        The text in the doc reads:

                         

                        runs=1500&moneys=$23000

                         

                        My movie clip (placed on the main timeline) instance is "Runnin"

                        My dynamic text field (part of the main timeline) instance is "guys"

                         

                        My code in frame 1 of the main timeline is below:

                         

                        loadVariablesNum("http://www.bakerdstreamingvid.com/runr.txt",0);
                        "runr.txt".onLoad=function(){
                        if(runs==0){
                          Runnin.gotoAndPlay(1);
                        } else if(runs==1){
                          Runnin.gotoAndPlay(1);
                        } else if(runs==2){
                          Runnin.gotoAndPlay(2);
                        } else if(runs==3){
                          Runnin.gotoAndPlay(3);
                        } else if(runs==4){
                          Runnin.gotoAndPlay(3);
                        } else if(runs==5){
                          Runnin.gotoAndPlay(4);
                        } else if(runs==6){
                          Runnin.gotoAndPlay(5);
                        } else if(runs==7){
                          Runnin.gotoAndPlay(6);
                        } else if(runs==8){
                          Runnin.gotoAndPlay(7);
                        } else if(runs==9){
                          Runnin.gotoAndPlay(8);
                        } else if(runs==10){
                          Runnin.gotoAndPlay(9);
                        } else if(runs==11){
                          Runnin.gotoAndPlay(10);
                        } else if(runs==12){
                          Runnin.gotoAndPlay(11);
                        } else if(runs==13){
                          Runnin.gotoAndPlay(12);
                        } else if(runs==14){
                          Runnin.gotoAndPlay(12);
                        } else if(runs==15){
                          Runnin.gotoAndPlay(13);
                        } else if(runs==16){
                          Runnin.gotoAndPlay(13);
                        } else if(runs==17){
                          Runnin.gotoAndPlay(14);
                        } else if(runs==18){
                          Runnin.gotoAndPlay(15);
                        } else if(runs==19){
                          Runnin.gotoAndPlay(16);
                        } else if(runs==20){
                          Runnin.gotoAndPlay(17);
                        } else if(runs==21){
                          Runnin.gotoAndPlay(18);
                        } else if(runs==22){
                          Runnin.gotoAndPlay(19);
                        } else if(runs==23){
                          Runnin.gotoAndPlay(20);
                        } else if(runs==24){
                          Runnin.gotoAndPlay(21);
                        } else if(runs==25){
                          Runnin.gotoAndPlay(22);
                        } else if(runs==26){
                          Runnin.gotoAndPlay(22);
                        } else if(runs==27){
                          Runnin.gotoAndPlay(23);
                        } else if(runs==28){
                          Runnin.gotoAndPlay(24);
                        } else if(runs==29){
                          Runnin.gotoAndPlay(24);
                        } else if((runs==30) || (runs>30)){
                          Runnin.gotoAndPlay(25);
                        }
                        }

                        • 9. Re: Text File Controlling Movie Timeline
                          kglad Adobe Community Professional & MVP

                          you'll need to use preload code to make sure the goto frame is loaded.

                           

                          for your loading code use:

                           

                          var sendLV:LoadVars=new LoadVars();

                          var receiveLV:LoadVars=new LoadVars()

                           

                          receiveLV.onLoad=function(){

                          Runnin.gotoAndPlay(1+Math.floor(runs/1000));

                          }

                           

                          sendLV.sendAndLoad("runr.text",receiveLV,"POST");

                          • 10. Re: Text File Controlling Movie Timeline
                            thereiter Level 1

                            Which part of my code needs to be replaced with yours?

                            I've replaced the entire code in my FLA with yours and neither the dynamic text field nor the animation in the MC run.

                            Thanks for all your help.

                            • 11. Re: Text File Controlling Movie Timeline
                              kglad Adobe Community Professional & MVP

                              replace all your code with the code i showed.  also, correct that text file name typo.  that should be

                               

                              runr.txt

                               

                              not

                               

                              runr.text

                              • 12. Re: Text File Controlling Movie Timeline
                                thereiter Level 1

                                Thanks for the help. Neither the dynamic text filed nor the animation are behaving correctly, however. He is the code in the 1st frame of the main timeline:

                                 

                                var sendLV:LoadVars=new LoadVars();
                                var receiveLV:LoadVars=new LoadVars()
                                receiveLV.onLoad=function(){
                                Runnin.gotoAndStop(1+Math.floor(runs/500));
                                }
                                sendLV.sendAndLoad("http://www.bakerdstreamingvid.com/runr.txt",receiveLV,"POST");

                                 

                                On the main timeline is the dynamic text field and an instance of the MC. Should I move the dynamic text to inside the MC? As mentioned before this is AS1.

                                 

                                Thanks again.

                                • 13. Re: Text File Controlling Movie Timeline
                                  kglad Adobe Community Professional & MVP

                                  add the Number function below and what's the following trace function show:


                                  var sendLV:LoadVars=new LoadVars();

                                  var receiveLV:LoadVars=new LoadVars()


                                  receiveLV.onLoad=function(){

                                  trace(Runnin+" "+Number(runs)+" "+runs.length+" "+runs);

                                  Runnin.gotoAndPlay(1+Math.floor(Number(runs)/1000));

                                  }


                                  sendLV.sendAndLoad("runr.txt",receiveLV,"POST");

                                  • 14. Re: Text File Controlling Movie Timeline
                                    thereiter Level 1

                                    I've replaced all the code with your suggestion, but still am not getting either the text field or the animation to work as expected. I didn't see the trace return anywhere. Nothing popped up in Compiler Errors panel or in the swf. Thoughts?

                                     

                                    Can I send you the FLA and .txt for further inspection?

                                     

                                    I am stumped. Thanks for all of your help with this issue.

                                    • 15. Re: Text File Controlling Movie Timeline
                                      kglad Adobe Community Professional & MVP

                                      you're not loading anything.

                                       

                                      you either have a file name and/or path error.

                                      • 16. Re: Text File Controlling Movie Timeline
                                        thereiter Level 1

                                        Thanks again KGLAD. I couldn't get the Math to work correctly for what I needed. The issue was creating the specific LoadVars as you were hinting at. See the final code below. Note that I added a second LoadVar to operate 2 graphs from the same .txt.

                                         

                                        loadVariablesNum("http://www.bakerdstreamingvid.com/runr.txt",0);
                                        run=new LoadVars();
                                        run.onLoad=function(){
                                        if(runs==0){
                                          Runnin.gotoAndStop(1);
                                        } else if(runs==1){
                                          Runnin.gotoAndStop(1);
                                        } else if(runs==2){
                                          Runnin.gotoAndStop(2);
                                        } else if(runs==3){
                                          Runnin.gotoAndStop(3);
                                        } else if(runs==4){
                                          Runnin.gotoAndStop(3);
                                        } else if(runs==5){
                                          Runnin.gotoAndStop(4);
                                        } else if(runs==6){
                                          Runnin.gotoAndStop(5);
                                        } else if(runs==7){
                                          Runnin.gotoAndStop(6);
                                        } else if(runs==8){
                                          Runnin.gotoAndStop(7);
                                        } else if(runs==9){
                                          Runnin.gotoAndStop(8);
                                        } else if(runs==10){
                                          Runnin.gotoAndStop(9);
                                        } else if(runs==11){
                                          Runnin.gotoAndStop(10);
                                        } else if(runs==12){
                                          Runnin.gotoAndStop(11);
                                        } else if(runs==13){
                                          Runnin.gotoAndStop(12);
                                        } else if(runs==14){
                                          Runnin.gotoAndStop(12);
                                        } else if(runs==15){
                                          Runnin.gotoAndStop(13);
                                        } else if(runs==16){
                                          Runnin.gotoAndStop(13);
                                        } else if(runs==17){
                                          Runnin.gotoAndStop(14);
                                        } else if(runs==18){
                                          Runnin.gotoAndStop(15);
                                        } else if(runs==19){
                                          Runnin.gotoAndStop(16);
                                        } else if(runs==20){
                                          Runnin.gotoAndStop(17);
                                        } else if(runs==21){
                                          Runnin.gotoAndStop(18);
                                        } else if(runs==22){
                                          Runnin.gotoAndStop(19);
                                        } else if(runs==23){
                                          Runnin.gotoAndStop(20);
                                        } else if(runs==24){
                                          Runnin.gotoAndStop(21);
                                        } else if(runs==25){
                                          Runnin.gotoAndStop(22);
                                        } else if(runs==26){
                                          Runnin.gotoAndStop(22);
                                        } else if(runs==27){
                                          Runnin.gotoAndStop(23);
                                        } else if(runs==28){
                                          Runnin.gotoAndStop(24);
                                        } else if(runs==29){
                                          Runnin.gotoAndStop(24);
                                        } else if((runs==30) || (runs>30)){
                                          Runnin.gotoAndStop(25);
                                        }
                                        }
                                        run.load("http://www.bakerdstreamingvid.com/runr.txt");
                                        coin=new LoadVars();
                                        coin.onLoad=function(){
                                        if(moneys==0){
                                          Cash.gotoAndStop(1);
                                        } else if((moneys>0) && (moneys<251)){
                                          Cash.gotoAndStop(2);
                                        } else if((moneys>250) && (moneys<500)){
                                          Cash.gotoAndStop(3);
                                        } else if((moneys>499) && (moneys<750)){
                                          Cash.gotoAndStop(4);
                                        } else if((moneys>749) && (moneys<1000)){
                                          Cash.gotoAndStop(5);
                                        } else if((moneys>999) && (moneys<1250)){
                                          Cash.gotoAndStop(6);
                                        } else if((moneys>1249) && (moneys<1500)){
                                          Cash.gotoAndStop(7);
                                        } else if((moneys>1499) && (moneys<1750)){
                                          Cash.gotoAndStop(8);
                                        } else if((moneys>1749) && (moneys<2000)){
                                          Cash.gotoAndStop(9);
                                        } else if((moneys>1999) && (moneys<2250)){
                                          Cash.gotoAndStop(10);
                                        } else if((moneys>2249) && (moneys<2500)){
                                          Cash.gotoAndStop(11);
                                        } else if((moneys>2499) && (moneys<2750)){
                                          Cash.gotoAndStop(12);
                                        } else if((moneys>2749) && (moneys<3000)){
                                          Cash.gotoAndStop(13);
                                        } else if((moneys>29990) && (moneys<3250)){
                                          Cash.gotoAndStop(14);
                                        } else if((moneys>3249) && (moneys<3500)){
                                          Cash.gotoAndStop(15);
                                        } else if((moneys>3499) && (moneys<3750)){
                                          Cash.gotoAndStop(16);
                                        } else if((moneys>3749) && (moneys<4000)){
                                          Cash.gotoAndStop(17);
                                        } else if((moneys>3999) && (moneys<4250)){
                                          Cash.gotoAndStop(18);
                                        } else if((moneys>4249) && (moneys<4500)){
                                          Cash.gotoAndStop(19);
                                        } else if((moneys>4499) && (moneys<4750)){
                                          Cash.gotoAndStop(20);
                                        } else if((moneys>4749) && (moneys<5000)){
                                          Cash.gotoAndStop(21);
                                        } else if((moneys>4999) && (moneys<5250)){
                                          Cash.gotoAndStop(22);
                                        } else if((moneys>5249) && (moneys<5500)){
                                          Cash.gotoAndStop(23);
                                        } else if((moneys>5499) && (moneys<6000)){
                                          Cash.gotoAndStop(24);
                                        } else if((moneys==6000) || (moneys>6000)){
                                          Cash.gotoAndStop(25);
                                        }
                                        }
                                        coin.load("http://www.bakerdstreamingvid.com/runr.txt");

                                        • 17. Re: Text File Controlling Movie Timeline
                                          kglad Adobe Community Professional & MVP

                                          you're welcome.