4 Replies Latest reply on Sep 12, 2007 11:38 AM by Newsgroup_User

    retreiving flashVars without knowing how many there are

    Level 7
      Hi all
      my question is simple:

      how to retreive flashVars in actionScript (passed via the flasVars param), if I don't know what the
      names and number of these variables are?

      For example, I have a dynamically generated list of flash vars, which depending on the cisrcumstance
      could be:

      var1=bar&var2=foo

      but could as well be:

      var1=bar&var2=foo&var3=blah&var4=something

      how do I determine the vars names and number in actionScript?

      Thanks for your help

      --
      seb ( ---@webtrans1.com)
      http://webtrans1.com | high-end web design

      An Ingenious WebSite Builder: http://sitelander.com
        • 1. Re: retreiving flashVars without knowing how many there are
          Level 7
          The vars will be defined, or not, within Flash. So you could set up a loop
          that iterates from 1 to some maximum and store the results in an array if
          the var is defined and break out of the loop as soon as you find the first
          undefined one:

          var varArray = [];
          var maxVars = 101;
          for(var i = 1; i < maxVars; i++){
          if(this["var"+i] != undefined){
          varArray.push(this["var"+i]);
          }else{
          break;
          }
          }


          HTH



          --
          Dave -
          Head Developer
          http://www.blurredistinction.com
          Adobe Community Expert
          http://www.adobe.com/communities/experts/


          • 2. Re: retreiving flashVars without knowing how many there are
            Level 7
            DMennenoh **AdobeCommunityExpert** wrote:
            > The vars will be defined, or not, within Flash. So you could set up a loop
            > that iterates from 1 to some maximum and store the results in an array if
            > the var is defined and break out of the loop as soon as you find the first
            > undefined one:
            >
            > var varArray = [];
            > var maxVars = 101;
            > for(var i = 1; i < maxVars; i++){
            > if(this["var"+i] != undefined){
            > varArray.push(this["var"+i]);
            > }else{
            > break;
            > }
            > }
            >
            >
            > HTH
            >
            >
            >

            thanks, that helps a bit, but in my example, the vars names where "var1" "var2" just for clarity. In
            fact, the var names could really be anything, like "advertising" or "coconut"...

            How would I retreive the var names if I don;t know them in advance?

            --
            seb ( ---@webtrans1.com)
            http://webtrans1.com | high-end web design

            An Ingenious WebSite Builder: http://sitelander.com
            • 3. Re: retreiving flashVars without knowing how many there are
              Greg Dove Level 4
              @Dave: that works if the naming convention "var"+i is followed. But the original post hinted at unknown names.

              If the very first code to execute in an as2 swf is like this then it will pick up unknown names. Here I've made a copy of the variables inside a new flashVars Object... that's not really necessary - the index of names as an array is the most important part I guess because it gives you the number of variables and how to access them.

              • 4. Re: retreiving flashVars without knowing how many there   are
                Level 7
                GWD wrote:
                > @Dave: that works if the naming convention "var"+i is followed. But the
                > original post hinted at unknown names.
                >
                > If the very first code to execute in an as2 swf is like this then it will pick
                > up unknown names. Here I've made a copy of the variables inside a new flashVars
                > Object... that's not really necessary - the index of names as an array is the
                > most important part I guess because it gives you the number of variables and
                > how to access them.
                >
                >
                >
                > var flashVars = new Object();
                > flashVars._index=new Array();
                > for (var item in this){
                > if ((MovieClip.prototype[item]==undefined) && (item!="flashVars") &&
                > (item!="$version")){
                > flashVars[item]=this[item]
                > flashVars._index.push(item)
                > }
                > }
                >
                > trace(flashVars._index)
                >

                thanks for this.
                I'm not too good with AS though - what's the MovieClip.prototype doing here?

                If I just wanted to make an array of the vars name and values, what would I use?

                would this code be enough?

                flashVars._index=new Array();

                is _index in the line above some special AS function, or is it a variable name?...

                thanks for your help.

                --
                seb ( ---@webtrans1.com)
                http://webtrans1.com | high-end web design

                An Ingenious WebSite Builder: http://sitelander.com