4 Replies Latest reply on May 16, 2006 2:44 AM by rechtut

    accesing externally loaded variables

    rechtut Level 1
      i would greatly appreciate a pointer or two as i am having a painful transition to AS2.0

      an 8k zip test is at: www.cyan-animatica.com/v2/exttest.zip //(wasn`t there an option back in macromedia days to attach a file?)


      i am having a poblem accesing externally loaded variables :

      A.--------------------------------------------------------------------
      the external .txt has folowing content:

      &a1_0=hello&a1_1=bye&a1_2=whatever


      B.--------------------------------------------------------------------
      loaded on the first frame thus:

      var thumbs:LoadVars = new LoadVars();
      thumbs.onLoad = function(success:Boolean):Void {
      if (success) {
      //
      trace("LoadVars loaded successfully: "+this.loaded);
      } else {
      trace("Error");
      }
      };
      thumbs.load("my_externals.txt");


      C.--------------------------------------------------------------------
      if want to access one of 3 loaded variable hardcoding, this works just fine:

      trace(_root.thumbs.a1_1) //bye

      BUT i need to do this based on the mc/buton name that calls it:

      on (press) {
      var kk:String = _name;
      trace(_root.thumbs.kk);
      }


      i get UNDEFINED...obviously i am mixing datatypes if not worse



      pc win 2000
      flash prof for flash8 player[
        • 1. Re: accesing externally loaded variables
          blemmo Level 1
          Hi,

          I don't really understand the problem, but when you want to add vars to the LoadVars object, it has to be referenced correctly:
          on (press) {
          _root.thumbs.kk = _name;
          trace(_root.thumbs.kk);
          }

          Is that what you wanted to do?

          cheers,
          blemmo
          • 2. Re: accesing externally loaded variables
            rechtut Level 1
            thanks for a prompt reply, blemmo.

            you write:<<to ADD vars to the LoadVars object, it has to be referenced correctly

            what i want to do is READ vars from LoadVars object and referencing is exactly what is killing me

            sorry bout the lack of clarity. the zip would help (www.cyan-animatica.com/v2/exttest.zip)

            i am loading 3 variables into an object var thumbs:LoadVars
            from one external .txt file:
            a1_0=hello
            a1_1=bye
            a1_2=whatever

            i want to see the contens of let us say the second variable

            trace(_root.thumbs.a1_1);

            produces bye , perfectly - this is exactly what i want, but i want it based on a constructed reference

            so, i have button in an mc named "a1_1", the button script is:
            on (press) {
            var kk:String = _name;
            trace(kk); // produces a1_1
            trace(_root.thumbs.kk); //this should be same as _root.thumbs.a1_1 and produce the same result, but does not
            }

            i suspect that the problem is that kk is declared as string datatype, but no matter what i do i cannot get a result

            thanks for your help
            • 3. Re: accesing externally loaded variables
              TwiceAlive100
              Try this:
              on (press) {
              var kk:String = _name;
              trace(kk); // produces a1_1
              trace(_root.thumbs[kk]);//use brackets instead of referencing by "."
              }
              • 4. Re: accesing externally loaded variables
                rechtut Level 1
                thank you for you time and effort blemmo

                and thank you TwiceAlive100 - you are 100% on the money

                it just an array, isn´t it? and i was going at it ***-backwards