19 Replies Latest reply on Dec 3, 2007 5:25 AM by Greg Dove

    loading a variable to use as a path

    Deltafrog
      I can load variables into flash text fields but I can't use those variable in my action script. Heres what I'm trying to do. I have a top5.txt file that looks like this:

      &title1=L.A.M.B. FRAGRANCE
      &body1=National Geographic reminds us to stay Green - with a little help from Natalie Portmany Green
      &detailspanel1=
      &imagepath1=/topfiveimages/image1.jpg
      &videopath1=/topfivevideos/top1.flv

      I'm trying to pull the image/video path from the external .txt file so they can be alterd without opening flash.

      Heres what I tried in my first frame so you get a better idea of what I'm trying to do
      _root.loadVariables("top5.txt");
      _root.container1.loadMovie(imagepath1);

      Thanks in advance.
        • 1. Re: loading a variable to use as a path
          Greg Dove Level 4
          _root.loadVariables("top5.txt");

          takes some time... and actionscript doesn't wait for it (loading a file/results of a server script) is really slow compared to how many instructions you could execute while you were waiting.

          The best way to load your data is using LoadVars, like this:

          var myLV:LoadVars = new LoadVars();
          myLV.onLoad=function(success){
          if (success){
          _root.container1.loadMovie(this.imagepath1);

          } else {
          //we had a problem loading the data...
          }
          }
          myLV.load("top5.txt");
          • 2. Re: loading a variable to use as a path
            Greg Dove Level 4
            or maybe its easier to understand like this:

            var myLV:LoadVars = new LoadVars();
            myLV.onLoad=function(success){
            if (success){
            processLoadedVariables()
            } else {
            //we had a problem loading the data...
            }
            }
            myLV.load("top5.txt");

            function processLoadedVariables(){
            _root.container1.loadMovie(myLV.imagepath1);

            _root.titleTF.text=myLV.title1;

            //etcetera

            }
            • 3. Re: loading a variable to use as a path
              Deltafrog Level 1
              Thanks a lot GWD. I think I'm doing everything correct but I keep getting a error:
              Error opening URL "file:///H|/Clients/Dogmatic/dogmatic%5Fvideo/topfiveimages/image1.jpg

              I'm sure the file is in the right location but still no luck.
              • 4. Re: loading a variable to use as a path
                Deltafrog Level 1
                Got it thanks!

                AS:
                var myLV:LoadVars = new LoadVars();
                myLV.onLoad = function(success) {
                if (success) {
                processLoadedVariables();
                } else {
                ///Problem loading
                }
                };
                myLV.load("top5.txt");
                function processLoadedVariables() {
                trace(myLV.imagepath1);
                _root.container1.loadMovie(myLV.imagepath1);
                }

                Text file:
                &imagepath1=topfiveimages/image1.jpg
                • 5. Re: loading a variable to use as a path
                  Deltafrog Level 1
                  Oh no! When I add more vars to the .txt file its doesn't find the image. Any thoughts?

                  Text File:
                  &imagepath1=topfiveimages/image1.jpg
                  &imagepath2=topfiveimages/image2.jpg
                  &imagepath3=topfiveimages/image3.jpg
                  &imagepath4=topfiveimages/image4.jpg
                  &imagepath5=topfiveimages/image5.jpg
                  • 6. Re: loading a variable to use as a path
                    Greg Dove Level 4
                    give it a try without the linebreaks:

                    &imagepath1=topfiveimages/image1.jpg&imagepath2=topfiveimages/image2.jpg&imagepath3=topfiv eimages/image3.jpg&imagepath4=topfiveimages/image4.jpg&imagepath5=topfiveimages/image5.jpg
                    • 7. Re: loading a variable to use as a path
                      Deltafrog Level 1
                      Beautiful....its just beautiful. Man I need to start using this forum more. Thanks you so much.
                      • 8. Re: loading a variable to use as a path
                        Deltafrog Level 1
                        One more question. I was wondering if I need to do anything special to make an array from these paths. Its doesn't seem to work by just replacing the absolute path. Thanks so much.


                        When I trace (myLV.videopath1) I get the correct result but it doesn't translate when I trace the array . trace(videoArray[myNumber]);


                        New code I just tried:
                        var videoArray = new Array();
                        videoArray[0] = myLV.imagepath1;
                        videoArray[1] = myLV.imagepath2;
                        videoArray[2] = myLV.imagepath3;
                        videoArray[3] = myLV.imagepath4;
                        videoArray[4] = myLV.imagepath5;

                        Previous working code:
                        var videoArray = new Array();
                        videoArray[0] = "topfivevideos/top4.flv";
                        videoArray[1] = "topfivevideos/top4.flv";
                        videoArray[2] = "topfivevideos/top3.flv";
                        videoArray[3] = "topfivevideos/top2.flv";
                        videoArray[4] = "topfivevideos/top1.flv";

                        text file:
                        &videopath1="topfivevideos/top1.flv"&videopath2="topfivevideos/top2.flv"&videopath3="topfi vevideos/top3.flv"&videopath4="topfivevideos/top4.flv"&videopath5="topfivevideos/top5.flv"
                        &imagepath1=topfiveimages/image1.jpg&imagepath2=topfiveimages/image2.jpg&imagepath3=topfiv eimages/image3.jpg&imagepath4=topfiveimages/image4.jpg&imagepath5=topfiveimages/image5.jpg &imagepath6=topfiveimages/image6.jpg
                        • 9. Re: loading a variable to use as a path
                          Deltafrog Level 1
                          New code I just tried:*
                          var videoArray = new Array();
                          videoArray[0] = myLV.videopath1;
                          videoArray[1] = myLV.videopath2;
                          videoArray[2] = myLV.videopath3;
                          videoArray[3] = myLV.videopath4;
                          videoArray[4] = myLV.videopath5;
                          • 10. loading a variable to use as a path
                            Greg Dove Level 4
                            Make sure you put this line:

                            var videoArray = new Array();

                            Outside the myLV.onLoad function

                            Otherwise it is a local variable that only exists inside that function and is not accessible beyond that scope.

                            You could just call a function from the myLV.onLoad function ("event handler") to do it all. It has to be called or executed in some way after myLV.onLoad has run (either within myLV.onLoad or as a call to another function from myLV.onLoad)
                            • 11. Re: loading a variable to use as a path
                              Deltafrog Level 1
                              #include "mc_tween2.as"
                              //AS Variables and load movie
                              var myLV:LoadVars = new LoadVars();
                              myLV.onLoad = function(success) {
                              if (success) {
                              processLoadedVariables();
                              trace(myLV.imagepath1);
                              trace(myLV.imagepath2);
                              trace(myLV.imagepath3);
                              trace(myLV.imagepath4);
                              trace(myLV.imagepath5);
                              trace(myLV.imagepath6);
                              trace(myLV.videopath1);
                              trace(myLV.videopath2);
                              trace(myLV.videopath3);
                              trace(myLV.videopath4);
                              trace(myLV.videopath5);
                              } else {
                              ///Problem loading
                              }
                              };
                              _root.loadVariables("topfivecopy/top5.txt");
                              myLV.load("top5.txt");
                              function processLoadedVariables() {
                              _root.container1.loadMovie(myLV.imagepath1);
                              _root.container2.loadMovie(myLV.imagepath2);
                              _root.container3.loadMovie(myLV.imagepath3);
                              _root.container4.loadMovie(myLV.imagepath4);
                              _root.container5.loadMovie(myLV.imagepath5);
                              _root.container6.loadMovie(myLV.imagepath6);

                              }
                              //////////////
                              //myFlvPlayer.playButton = playbtn;
                              //myFlvPlayer.pauseButton = pausebtn;
                              //myFlvPlayer.playPauseButton = playpausebtn;
                              myFlvPlayer.stopButton = stopbtn;
                              myFlvPlayer.muteButton = muteBtn;
                              myFlvPlayer.backButton = backbtn;
                              //myFlvPlayer.forwardButton = forbtn;
                              myFlvPlayer.volumeBar = volbar;
                              myFlvPlayer.seekBar = seekbar;
                              myFlvPlayer.bufferingBar = bufbar;
                              myFlvPlayer.ratioButton = ratioBtn;
                              flvPlayer.rewindButton = rewindBtn;
                              //LowerTitleArray
                              //////////////////////////
                              var titleArray = new Array();
                              titleArray[0] = "f5";
                              titleArray[1] = "f4";
                              titleArray[2] = "f3";
                              titleArray[3] = "f2";
                              titleArray[4] = "f1";
                              titleNumber = 4;
                              trace(titleArray[titleNumber]);
                              myText = titleArray[titleNumber];
                              //////////////////////////
                              //////////////////////////
                              var videoArray = new Array();
                              videoArray[0] = myLV.imagepath6;
                              videoArray[1] = "topfivevideos/top4.flv";
                              videoArray[2] = "topfivevideos/top3.flv";
                              videoArray[3] = "topfivevideos/top2.flv";
                              videoArray[4] = "topfivevideos/top1.flv";
                              /////////////////////////
                              /////////////////////////
                              //titleNumber = 4;
                              //myFlvPlayer.setFLV(videoArray[myNumber]);
                              ///////////////////////
                              backbtn_cover.onRelease = function() {
                              // Subtract 1 from my number
                              titleNumber = titleNumber-1;
                              myNumber = myNumber-1;
                              // If myNumber is equal to or less than 0 then...
                              if (myNumber<=0) {
                              // Display the following
                              myText = titleArray[titleNumber];
                              // Makes the back button invisible
                              backbtn_cover._visible = 0;
                              backbtn.alphaTo(20, 1, "linear");
                              // Makes the forward button visible
                              forwardbtn_cover._visible = 1;
                              forwardbtn.alphaTo(100, 1, "linear");
                              // If myNumber is greater than or equal to 5 then...
                              } else if (myNumber>=4) {
                              // Reset myNumber to 4 and ...
                              myNumber = 4;
                              // Display the Array listing for myNumber (which is 4)
                              myText = titleArray[titleNumber];
                              // Makes the back button visible
                              backbtn_cover._visible = 1;
                              backbtn.alphaTo(100, 1, "linear");
                              // Makes the forward button invisible
                              forwardbtn._visible = 0;
                              forwardbtn.alphaTo(20, 1, "linear");
                              // Otherwise ...
                              } else {
                              // Display the Array listing for myNumber
                              myText = titleArray[titleNumber];
                              // Makes the back button visible
                              backbtn_cover._visible = 1;
                              backbtn.alphaTo(100, 1, "linear");
                              // Makes the forward button visible
                              forwardbtn_cover._visible = 1;
                              forwardbtn.alphaTo(100, 1, "linear");
                              // Close if-else statement
                              }
                              // Close on(release) statement
                              myFlvPlayer.setFLV(videoArray[videoNumber]);
                              myText = titleArray[titleNumber];
                              //trace(videoArray[myNumber]);
                              _root.title_mc.gotoAndStop(titleArray[titleNumber]);
                              _root.slidePanel.panel_titles.gotoAndStop(myText);
                              };
                              //////////////
                              forwardbtn_cover.onRelease = function() {
                              // Add 1 to my number
                              titleNumber = titleNumber+1;
                              myNumber = myNumber+1;
                              // If myNumber is greater than 4 then...
                              if (myNumber>=4) {
                              // Resets myNumber to 4
                              myNumber = 4;
                              // Display the Array listing for myNumber (which is 4)
                              myText = myText=titleArray[titleNumber];
                              // Makes the back button visible
                              backbtn_cover._visible = 1;
                              backbtn.alphaTo(100, 1, "linear");
                              // Makes the forward button invisible
                              forwardbtn_cover._visible = 0;
                              forwardbtn.alphaTo(20, 1, "linear");
                              // If myNumber is equal to or less than 0 then...
                              } else if (myNumber<=0) {
                              //Reset myNumber to: 0 and ...
                              myNumber = 0;
                              // Display the Array listing for myNumber (which is 0)
                              myText = titleArray[titleNumber];
                              // Makes the back button invisible
                              backbtn_cover._visible = 0;
                              backbtn.alphaTo(20, 1, "linear");
                              // Makes the forward button visible
                              forwardbtn_cover._visible = 1;
                              forwardbtn.alphaTo(100, 1, "linear");
                              // Otherwise ...
                              } else {
                              // Display the Array listing for myNumber
                              myText = titleArray[titleNumber];
                              // Makes the back button visible
                              backbtn_cover._visible = 1;
                              backbtn.alphaTo(100, 1, "linear");
                              // Makes the forward button visible
                              forwardkbtn_cover._visible = 1;
                              forwardbtn.alphaTo(100, 1, "linear");
                              // Close if-else statement
                              }
                              // Close on(release) statement
                              myFlvPlayer.setFLV(videoArray[myNumber]);
                              myText = titleArray[titleNumber];
                              trace(videoArray[myNumber]);
                              //trace(titleArray[titleNumber]);
                              _root.title_mc.gotoAndStop(titleArray[titleNumber]);
                              _root.slidePanel.panel_titles.gotoAndStop(myText);
                              };
                              //////
                              var listenerObject:Object = new Object();
                              listenerObject.rewind = function(eventObject:Object) {
                              //
                              };
                              myFlvPlayer.addEventListener("rewind", listenerObject);
                              rewindBtn.onRelease = function() {
                              myFlvPlayer.rewindFlv(10);
                              };


                              Thansk agian.
                              Heres my code. I just cant seem to get the paths to switch out for the absolute paths. Though the trace works. :( trace(myLV.videopath3);


                              Should I use XML to load the vars or is that not an issue?
                              • 12. Re: loading a variable to use as a path
                                Deltafrog Level 1
                                The code above has the absolute paths in its Videoarray.
                                • 13. Re: loading a variable to use as a path
                                  Twinbird24 Level 1
                                  I have the same problem but I can't get anything to work for me. I have a file called variables.txt that his this in it:

                                  imageDirectory=images

                                  this is the AS(2.0) i have to load the image into a movie clip on the stage called image01_MC

                                  AS:

                                  var myMCL:MovieClipLoader = new MovieClipLoader();

                                  var myLV:LoadVars = new LoadVars();
                                  myLV.onLoad = function(success) {
                                  if (success) {
                                  processLoadedVariables();
                                  } else {
                                  ///Problem loading
                                  }
                                  };
                                  myLV.load("variables.txt");
                                  function processLoadedVariables() {
                                  trace(myLV.imageDirectory);
                                  _root.myMCL.loadClip(myLV.imageDirectory+"/image01.jpg", _root.image01_MC);
                                  }

                                  //I can use the variable (imageDirectory which = image) in text files and it will display the variable but when I try to use it in a directory path it doesn't work.
                                  the image path is images/image01.jpg and the swf file is in the folder before the images folder. this is what i get in the output panel:

                                  images


                                  Error opening URL 'file:///F|/Documents%20and%20Settings/K/My%20Documents/%5FARK%20Designs/%5Fwebsites/Flor esta%20Flowers/flowerAnimBar/images

                                  /image01.jpg'

                                  it says error opening file even though it seems like the path to the image is correct and the image (image01.jpg) is in that directory. Someone please help. Thanks
                                  • 14. Re: loading a variable to use as a path
                                    Deltafrog Level 1
                                    Got it workin!. I used XML to pass variables and just used the titleNumber already in place. So easy once you figure it out. Thanks a lot GWD!!

                                    Actionscript for my back and forth btns:
                                    myFlvPlayer.setFLV(xmlNode.childNodes[titleNumber].attributes.urlz);

                                    The basic XML:
                                    <pic>
                                    <image urlz="topfivevideos/top1.flv"></image>
                                    <image urlz="topfivevideos/top2.flv"></image>
                                    <image urlz="topfivevideos/top3.flv"></image>
                                    <image urlz="topfivevideos/top4.flv"></image>
                                    <image urlz="topfivevideos/top5.flv"></image>
                                    </pic>
                                    • 15. Re: loading a variable to use as a path
                                      Twinbird24 Level 1
                                      I still don't get it, it's not working for me.

                                      This is the correct path to the image:

                                      F:\Documents and Settings\K\My Documents\_ARK Designs\_websites\Floresta Flowers\flowerAnimBar\images\image01.jpg

                                      This is what is in the vars.txt text file (in theflowerAnimBar directory):

                                      imageDirectory=images

                                      This is the action script I have to load the image into the image01_MC movie clip on the stage:

                                      var myLV:LoadVars = new LoadVars();
                                      myLV.onLoad = function(success) {
                                      if (success){
                                      processLoadedVariables()
                                      } else {
                                      imgTxt.text = "There is a problem loaded the requested informaion";
                                      }
                                      }

                                      myLV.load("vars.txt");

                                      function processLoadedVariables(){
                                      loadMovie(myLV.imageDirectory+"/image01.jpg", image01_MC);
                                      trace(myLV.imageDirectory);
                                      }

                                      //when I trace the variable I get the right one; images. When I look at the output panel it seems like there should be no error but for some reason Flash just can't load the fucken image

                                      This is what it says in the output panel:

                                      images


                                      Error opening URL 'file:///F|/Documents%20and%20Settings/K/My%20Documents/%5FARK%20Designs/%5Fwebsites/Flor esta%20Flowers/flowerAnimBar/images

                                      /image01.jpg'


                                      • 16. Re: loading a variable to use as a path
                                        Greg Dove Level 4
                                        @DeltaFrog: great to hear

                                        @Twinbird: Normally you should start your own thread with a new issue like this. Also its helpful to use nice language, even if you're annoyed that you can't get it to work. Your language doesn't offend me but it might offend others, which will mean that you are less likely to receive help. It could make you more annoyed.
                                        Your problem looks like it might be related to linebreaks, and it seems you're using a windows editor, maybe notepad for your text file. Scroll up and look at my 3rd post on this page. See if that helps.
                                        • 17. Re: loading a variable to use as a path
                                          Greg Dove Level 4
                                          Just to be clear:

                                          in vars.txt:

                                          imageDirectory=images[you have a linebreak here, delete it]
                                          • 18. Re: loading a variable to use as a path
                                            Twinbird24 Level 1
                                            Thanks alot GWD I got it to work!!!!
                                            • 19. Re: loading a variable to use as a path
                                              Greg Dove Level 4
                                              @twinbird great to hear, you're welcome