28 Replies Latest reply on Aug 14, 2009 8:17 AM by rlinsurf1

    Set #include dynamically?

    rlinsurf1 Level 1

      I have a pre-made solution I purchased. But it only works when it's variables are all loaded from a #include .txt.

       

      Here's a sample file:

       

      http://charlesnewmanpubl.com/Sweethearts_On_Parade_BRGK.txt

       

      It's all in the form of an include rather than a loadVars. Is there anyway to load this file with a loadVars?

        • 1. Re: Set #include dynamically?
          kglad Adobe Community Professional & MVP

          sure, you can load a text file using loadvars.  the text won't be available until loading is complete, though.

          1 person found this helpful
          • 2. Re: Set #include dynamically?
            rlinsurf1 Level 1

            I'm a total n00b. Can you tell me how to do that?

             

            I think I know how to test if it's complete, if that helps.

            • 3. Re: Set #include dynamically?
              kglad Adobe Community Professional & MVP

              var sendLV:LoadVars = new LoadVars();

              var receiveLV:LoadVars = new LoadVars();

               

              receiveLV.onData=function(src){

              //src will contain the contents of your textfield

              //if you use an onLoad() instead of onData(), you can retrieve name/value pairs

              }

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

              • 4. Re: Set #include dynamically?
                rlinsurf1 Level 1

                Hi--

                 

                This is the name of my .txt:  "Sweethearts_On_Parade_BRGK.txt". I tried it both as is, with a copy of the file at the root of the project folder, and as a URL, "http://charlesnewmanpubl.com/Sweethearts_On_Parade_BRGK.txt". I copied and pasted your code as is, with only the file name changed. I get this error both times:

                 

                Error opening URL 'http://charlesnewmanpubl.com/undefined'

                • 5. Re: Set #include dynamically?
                  kglad Adobe Community Professional & MVP

                  use a local path with the path being relative to the swf's embedding html file.  if you don't understand that, put your html, swf and text file in the same directory and use the file name without a path.

                  • 6. Re: Set #include dynamically?
                    rlinsurf1 Level 1

                    Ah, I can't do that. I need to load remote files.

                    • 7. Re: Set #include dynamically?
                      kglad Adobe Community Professional & MVP

                      then you may have cross-domain security issues to deal with.

                      • 8. Re: Set #include dynamically?
                        rlinsurf1 Level 1

                        It's basically a private site. It's just that I'm setting this up so the files can load dynamically, even if that's a remote server.

                        • 9. Re: Set #include dynamically?
                          rlinsurf1 Level 1

                          Oh, also, this is giving the error even when the .txt is at the root of the project locally.

                          • 10. Re: Set #include dynamically?
                            kglad Adobe Community Professional & MVP

                            copy and paste your error message.

                             

                            if it's the same as the one you posted above, copy and paste the code you used to load the text file.

                            • 11. Re: Set #include dynamically?
                              rlinsurf1 Level 1

                              Hi--

                               

                              Error opening URL 'http://charlesnewmanpubl.com/undefined'

                               

                               

                              Here's the code:

                               

                              I tried it both as a local file and as a URL:

                               

                               

                              var sendLV:LoadVars = new LoadVars();
                              var receiveLV:LoadVars = new LoadVars();
                              
                              receiveLV.onData=function(src){
                              //src will contain the contents of your textfield
                              //if you use an onLoad() instead of onData(), you can retrieve name/value pairs
                              }
                              sendLV.sendAndLoad("http://charlesnewmanpubl.com/Sweethearts_On_Parade_BRGK_i.txt",receiveLV,"POST");
                              

                               

                              and as

                               

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

                               

                              I believe the undefined is coming from the fact the .txt hasn't fully loaded before the init() function tries to play the file.

                              • 13. Re: Set #include dynamically?
                                kglad Adobe Community Professional & MVP

                                what init() function?  anything that uses that text file should be called from the onData method so you're sure loading is complete.

                                • 14. Re: Set #include dynamically?
                                  rlinsurf1 Level 1

                                  Sorry for not getting back to you.

                                   

                                  Ok, here's the top of the file. I should let you know, if I hadn't, that I'm trying to adapt someone else's solution.

                                   

                                  Here's the top of the code:

                                  
                                  var sendLV:LoadVars = new LoadVars();
                                  var receiveLV:LoadVars = new LoadVars();
                                  
                                  receiveLV.onData=function(src){
                                  //src will contain the contents of your textfield
                                  //if you use an onLoad() instead of onData(), you can retrieve name/value pairs
                                  }
                                  sendLV.sendAndLoad("http://charlesnewmanpubl.com/Sweethearts_On_Parade_BRGK_i.txt",receiveLV,"POST");
                                  
                                  
                                  //----------------------------------------------------
                                  
                                  var graphHolder : MovieClip
                                  var loadingTxt : MovieClip
                                  var sound : Sound
                                  var frameIndex : Number = 1
                                  var ampIndex : Number = 1
                                  var playing : Boolean = false
                                  var eqGraph : Boolean = true
                                  var soundIndex : Number = 0
                                  var graphWidth : Number = 70
                                  var graphHeight : Number = 35
                                  var graphGap : Number = 1
                                  var graphTopMargin : Number = 5
                                  var frameLoopInt : Number
                                  var loop:Boolean = true
                                  var startLoad:Boolean = false
                                  
                                  //initialisation function
                                  function init ()
                                  {
                                  
                                  
                                  

                                  In the midst of init() is where I think the problem is

                                   

                                   

                                  function playSound ()
                                  {
                                       if(!startLoad){ // sound not loaded
                                            startLoad = true
                                            this.loadingTxt._visible = true
                                            //use loadSound if the sound is an external .mp3.
                                            this.sound.loadSound ("http://charlesnewmanpubl.com/" + faFile, true);
                                       }
                                       this.playing = true
                                       this.sound.start (this.soundIndex / 1000)
                                  }
                                  

                                   

                                   

                                  The file is attached above.

                                  • 15. Re: Set #include dynamically?
                                    kglad Adobe Community Professional & MVP

                                    i assume faFile is defined in the text file.  if so, you should not call init() until the text file has completed loading:

                                     

                                     

                                     

                                     

                                    
                                    var sendLV:LoadVars = new LoadVars();
                                    var receiveLV:LoadVars = new LoadVars();

                                    receiveLV.onData=function(src){ //define faFile;
                                    init()
                                    } sendLV.sendAndLoad("http://charlesnewmanpubl.com/Sweethearts_On_Parade_BRGK_i.txt",receiveLV,"POST");


                                    //----------------------------------------------------

                                    I

                                    • 16. Re: Set #include dynamically?
                                      rlinsurf1 Level 1

                                      Yes, it is, that's the name of the .mp3.

                                       

                                      Sorry for being dense. I'm not sure what you mean by define. Isn't that this?

                                       

                                      var fa:LoadVars = new LoadVars();

                                       

                                      But you already have these:

                                       

                                      var sendLV:LoadVars = new LoadVars();
                                      var receiveLV:LoadVars = new LoadVars();
                                      

                                       

                                      I guess I'm confused.

                                      • 17. Re: Set #include dynamically?
                                        rlinsurf1 Level 1

                                        Ok. I think I got it. You meant like this?

                                         

                                        var sendLV:LoadVars = new LoadVars();
                                        var receiveLV:LoadVars = new LoadVars();
                                        
                                        receiveLV.onData=function(src){
                                        var faFile:String;
                                        init()
                                        }
                                        sendLV.sendAndLoad("http://charlesnewmanpubl.com/Sweethearts_On_Parade_BRGK_i.txt",receiveLV,"POST");
                                        
                                        
                                        

                                         

                                        This, frustratingly, still results in the undefined error for the .mp3.

                                        • 18. Re: Set #include dynamically?
                                          kglad Adobe Community Professional & MVP

                                          what's the output panel show when you use:

                                           


                                           

                                           

                                          var sendLV:LoadVars = new LoadVars();
                                          var receiveLV:LoadVars = new LoadVars();
                                           
                                          receiveLV.onData=function(src){
                                          trace(src);
                                          init() } sendLV.sendAndLoad("http://charlesnewmanpubl.com/Sweethearts_On_Parade_BRGK_i.txt",receiveLV,"POST");

                                           

                                          This, frustratingly, still results in the undefined error for the .mp3.

                                          • 19. Re: Set #include dynamically?
                                            rlinsurf1 Level 1

                                            faFile="Sweethearts_On_Parade_BRGK.mp3";
                                            fps=15;
                                            scale=100;
                                            smoothing=0;
                                            dBValues=0;
                                            stereo=0;
                                            lowLimit=20;
                                            highLimit=10000;
                                            bands=[[20, 226], [227, 554], [555, 968], [969, 1448], [1449, 1983], [1984, 2564], [2565, 3184], [3185, 3839], [3840, 4526], [4527, 5241], [5242, 5982], [5983, 6747], [6748, 7534], [7535, 8342], [8343, 9169], [9170, 10000]];
                                            numBands=16;
                                            scaleAllBands=0;
                                            
                                            amplitude=[0, 0, 69, 67, 33, 
                                            ...
                                            0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
                                            spectrum=[[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [30, 64, 70, 70, 70, 72, 74, 70, 74, 80, 72, 71, 70, 52, 40, 28], 
                                            ...
                                             0, 0, 0]];
                                            
                                            Error opening URL 'http://charlesnewmanpubl.com/undefined'
                                            

                                             

                                            ... denotes additional data.

                                            • 20. Re: Set #include dynamically?
                                              kglad Adobe Community Professional & MVP

                                              use:

                                               


                                               


                                               

                                               

                                              var sendLV:LoadVars = new LoadVars();
                                              var receiveLV:LoadVars = new LoadVars();
                                               
                                              receiveLV.onLoad=function(s){
                                              faFile = this.faFile;
                                              init() } sendLV.sendAndLoad("http://charlesnewmanpubl.com/Sweethearts_On_Parade_BRGK_i.txt",receiveLV,"POST");

                                               

                                              • 21. Re: Set #include dynamically?
                                                rlinsurf1 Level 1

                                                Improvement. I get no errors, but nothing plays or functions either. So I added a trace.

                                                 

                                                 

                                                var sendLV:LoadVars = new LoadVars();
                                                var receiveLV:LoadVars = new LoadVars();
                                                
                                                receiveLV.onLoad=function(s){
                                                faFile = this.faFile;
                                                trace("faFile found: " + faFile);
                                                init()
                                                }
                                                sendLV.sendAndLoad("http://charlesnewmanpubl.com/Sweethearts_On_Parade_BRGK_i.txt",receiveLV,"POST");
                                                

                                                 

                                                 

                                                But the trace is weird. Before adding the trace(faFile); I got no output whatsoever. But when I added the trace, I get:

                                                 

                                                 

                                                faFile found: "Sweethearts_On_Parade_BRGK.mp3";     //there is no variable key here, so this is actually "faFile". But why's the rest of the data here?
                                                fps=15;
                                                scale=100;
                                                smoothing=0;
                                                dBValues=0;
                                                stereo=0;
                                                lowLimit=20;
                                                highLimit=10000;
                                                bands=[[20, 226], [227, 554], [555, 968], [969, 1448], [1449, 1983], [1984, 2564], [2565, 3184], [3185, 3839], [3840, 4526], [4527, 5241], [5242, 5982], [5983, 6747], [6748, 7534], [7535, 8342], [8343, 9169], [9170, 10000]];
                                                numBands=16;
                                                scaleAllBands=0;
                                                
                                                amplitude=[0, 0, 
                                                ...
                                                , 0, 0, 0]];
                                                
                                                spectrum=[[0, 0, 
                                                
                                                ...
                                                , 0, 0, 0]];
                                                

                                                 

                                                 

                                                I checked very carefully. There are no other trace's in the code. When the trace is removed, there is no output.

                                                • 22. Re: Set #include dynamically?
                                                  rlinsurf1 Level 1

                                                  Ok. I found one problem. The trace was reading the whole file because it was in the include form. When I changed it to match the form for loadVars, the var was found, and the mp3 is now playing.

                                                   

                                                  But the data still isn't being displayed.

                                                   

                                                  Here's the file as it now is:

                                                   

                                                  http://charlesnewmanpubl.com/player_fa4.fla.zip

                                                   

                                                  I've got a bunch of other methods commented out. As well, there's some stuff not related to all the spectrum stuff. That's all commented as Not FA.

                                                  • 23. Re: Set #include dynamically?
                                                    kglad Adobe Community Professional & MVP

                                                    so faFile is correctly defined and your loadSound() argument is correct?  is your sound loading?

                                                     

                                                    p.s.  you won't be able to obtain any bytearray data.

                                                    • 24. Re: Set #include dynamically?
                                                      rlinsurf1 Level 1

                                                      Yep, it's loading fine.

                                                       

                                                      No, I hadn't realized that @ bytearray.

                                                      • 25. Re: Set #include dynamically?
                                                        kglad Adobe Community Professional & MVP

                                                        so, this thread is answered, correct?

                                                         

                                                        (getting bytearray sound data does cause a cross-domain security issue.  you can use the soundloadercontext parameter in the load() method and assign its checkPolicy property to true if the server has a cross-domain policy file to load.)

                                                        • 26. Re: Set #include dynamically?
                                                          rlinsurf1 Level 1

                                                          No, I don't think so. The data isn't being used. You mean I should start a new thread?

                                                           

                                                          As well, I actually don't understand what you said, sorry for the continuing n00bness

                                                           

                                                          If I understand any of it, all these files will be under the same domain, just different directories. Does that help?

                                                          • 27. Re: Set #include dynamically?
                                                            kglad Adobe Community Professional & MVP

                                                            if they're in the same domain, use a  relative path.  then no cross-domain xml file is needed.

                                                            • 28. Re: Set #include dynamically?
                                                              rlinsurf1 Level 1

                                                              I'm sorry if I'm not understanding. I don't think I'm using xml?

                                                               

                                                              Could you maybe give me an example of what you mean in my code and how to fix it?