4 Replies Latest reply on May 27, 2006 7:55 AM by Newsgroup_User

    LoadVars: sendAndLoad with only one instance?

    Level 7
      isn't it posible to send & receive vars to/from a web application using
      only 1 loadVars instance and the sendAndLoad method? if the answer is
      yes, why MM documentacion & examples uses 2 loadVars instances?

      tia,

      jdoe

      login.fla example in F8
      =======================
      ...
      /* define two instances of the LoadVars object.
      One is used to hold the variables being sent to the server-side script,
      and the other one is used to hold the variables returned by the
      LoadVars.sendAndLoad method. */

      var result_lv:LoadVars = new LoadVars();
      var login_lv:LoadVars = new LoadVars();
      // copy the value of the two TextInput components into the login_lv
      LoadVars instance.
      login_lv.username = username_ti.text;
      login_lv.password = password_ti.text;

      /* send the variables in the login_lv instance to the server-side script
      using the POST method (send as Form variables rather than along the URL)
      and place the results returned in the result_lv instance. */

      login_lv.sendAndLoad(" http://www.flash-mx.com/mm/login.cfm", result_lv,
      "POST");
      // When the results are received from the server...
      result_lv.onLoad = function(success:Boolean) {
      // If Flash is able to successfully send and load the variables from the
      server-side script...
      if (success) {
      ...
        • 1. Re: LoadVars: sendAndLoad with only one instance?
          blemmo Level 1
          It's possible with one object, but then the sent data will get replaced by the loaded data. Guess they used 2 objects in the Help to keep the sent data available, but if you don't need it anymore after sending it, it's just fine to use the same object to receive the server response.
          • 2. Re: LoadVars: sendAndLoad with only one instance?
            Level 7
            i'm almost sure the sent data will get replaced by loaded data only if
            properties have the same name. that's why i don't understand the
            neccessity of 2 instances

            blemmo wrote:

            > It's possible with one object, but then the sent data will get replaced by the
            > loaded data. Guess they used 2 objects in the Help to keep the sent data
            > available, but if you don't need it anymore after sending it, it's just fine to
            > use the same object to receive the server response.
            • 3. LoadVars: sendAndLoad with only one instance?
              Mad_Rhino
              Hi, do you still need help in using only one loadVars instance? if so heres something i just whipped up

              login_lv = new LoadVars();

              //The following code would be put on a Login button for example:
              login_lv.clear();
              login_lv.username = username_ti.text;
              login_lv.password = password_ti.text;
              login_lv.onLoad = loginDataLoaded;
              login_lv.sendAndLoad(" http://www.flash-mx.com/mm/login.cfm", login_lv, "POST");

              loginDataLoaded is the function where all the loaded data will be, so from this funciton you can error check etc for example..

              loginDataLoaded = function(){
              var loginData = this;

              //do your actions here
              }



              • 4. Re: LoadVars: sendAndLoad with only one instance?
                Level 7
                thanks Mad, i succeeded using one instance, just wondering if there's
                any advantage in using 2 as in MM examples

                Mad Rhino wrote:
                > Hi, do you still need help in using only one loadVars instance? if so heres
                > something i just whipped up
                >
                > login_lv = new LoadVars();
                >
                > //The following code would be put on a Login button for example:
                > login_lv.clear();
                > login_lv.username = username_ti.text;
                > login_lv.password = password_ti.text;
                > login_lv.onLoad = loginDataLoaded;
                > login_lv.sendAndLoad("<a target=_blank class=ftalternatingbarlinklarge
                > href=" http://www.flash-mx.com/mm/login.cfm",">http://www.flash-mx.com/mm/login.c
                > fm",</a> login_lv, "POST");
                >
                > loginDataLoaded is the function where all the loaded data will be, so from
                > this funciton you can error check etc for example..
                >
                > loginDataLoaded = function(){
                > var loginData = this;
                >
                > //do your actions here
                > }