12 Replies Latest reply on Aug 7, 2007 11:30 AM by raminu

    actionscript help

    raminu
      Actionscript part:
      var my_lv:LoadVars = new LoadVars();
      my_lv.onLoad = function(succes){
      if(succes){
      info_txt.text = this.litere;
      var dada = info_txt.text ;
      if (dada == "RO") {

      _root.motion_countries.play();

      }
      else {

      _root.country = 0;
      _root.motion_countries.play();

      }
      }
      }

      my_lv.load("http:/.....................something.php");

      ////////////
      So i receive a variable from a php file and a can see it in a dinamic text field call "info_txt"
      That work fine (I receive "RO".)
      What doesn't work:
      When i make the condition if(info_txt.text == "RO") it does'n do the right thing.
      But if i write in front the variable info_text="RO" it's works
      Can anyone tell me what i do wrong?
        • 1. Re: actionscript help
          Greg Dove Level 4
          I'm not sure I understand your question well.

          if(info_txt.text="RO")
          should normally be
          if(info_txt.text=="RO")

          i.e. == instead of =
          • 2. Re: actionscript help
            raminu Level 1
            I use "==", not this is the problem.
            My question is: why this script work's:
            /////////////////
            info_txt.text = "RO";
            var dada = info_txt.text ;
            if (dada == "RO") {.......................succes.......................
            /////////////////////////
            And this one does'n work:
            My question is: why this script work's:
            /////////////////
            info_txt.text = this.litere;
            var dada = info_txt.text ;
            if (dada == "RO") {.......................failed.......................
            /////////////////////////////
            "this.litere" meaning the variable i receive from php (i receive the right thing meaning "RO", because i can see it in dinamic text field in flash)
            • 3. Re: actionscript help
              Greg Dove Level 4
              OK... sorry now I understand.

              Check you haven't got any extra whitespace coming back from PHP e.g. "RO " or " RO" with extra spaces.

              info_txt.text = this.litere;
              trace (this.litere.length); //should show 2.
              var dada = info_txt.text ;
              • 4. Re: actionscript help
                raminu Level 1
                still d'ont work
                • 5. Re: actionscript help
                  Greg Dove Level 4
                  That doesn't fix it, it just helps you find where the problem is.

                  Do you have any extra whitespace or not? (did the trace show 3 or more)

                  If you change :

                  if (dada == "RO") {

                  to be:

                  if (this.litere== "RO") {

                  and it doesn't work, then the problem is with your PHP not giving you exactly "RO"



                  • 6. Re: actionscript help
                    Greg Dove Level 4
                    If you open your php script in a browser you should see something like

                    litere=RO

                    or

                    &litere=RO&

                    • 7. Re: actionscript help
                      Level 7
                      Instead of using the onLoad event, try using the onData event to test
                      for the download. The onLoad event it triggered when the download has
                      finished, but the text may not be fully formatted to the text space yet,
                      so when you test the contents of the text field, you get the wrong answer.
                      --
                      Rob

                      ___________
                      Rob Dillon
                      Adobe Community Expert
                      http://www.ddg-designs.com
                      412.243.9119
                      • 8. actionscript help
                        Greg Dove Level 4
                        @Rob: Is that the case? I thought onData (if you use it) occurs before the native parsing routine which calls onLoad when parsing has finished.

                        So onData could be used as you say to test the raw value being received - much like viewing it in a browser, but my understanding is that there is no way that onLoad occurs before parsing has finished. And if you use onData, you need to explicitly call onLoad or implement your own parsing routine (so its very useful if you just want to load raw text).

                        EDIT: I just checked. The documentation doesn't include an example, but my guess is that onData works the same way as the XML.onData - but instead of this.parseXML(src) it would use this.decode(src) before calling the onLoad handler.




                        • 9. Re: actionscript help
                          Level 7
                          I just did a quick local test using onData to assign the loaded text to
                          a dynamic text field, then assign the same text as the value of a
                          variable, then I tested the variable against the original text as in
                          your first post.

                          The text in the variable was the same as the downloaded text.

                          My code looks like this:

                          ------------
                          var my_lv:LoadVars = new LoadVars();
                          my_lv.onData = function(src:String) {
                          info_txt.text = src;
                          var dada = info_txt.text;
                          if(dada == "one,two,three,four") {
                          trace("yes");
                          }
                          }

                          my_lv.load("content.txt",my_lv,"GET");
                          -------------

                          --
                          Rob

                          ___________
                          Rob Dillon
                          Adobe Community Expert
                          http://www.ddg-designs.com
                          412.243.9119
                          • 10. actionscript help
                            Greg Dove Level 4
                            @Rob... I don't think the problem here is anything to do with the timing or whether assigning and and retreiving the value from the text property of the textfield is causing a problem.

                            The problem is that the the PHP code is not returning the correct value for the test. It is returning a value..... because its visible in the text field after assignment in the onLoad handler. And assigning the property to a text field's text property and retreiving it in very the next instruction is something I've never had an issue with (although I wouldn't be inclined to do it normally).

                            So all that's left is the value and what it's being compared with. Which to my mind means that there is some extra whitespace (because it looks OK in the textfield)


                            • 11. Re: actionscript help
                              Level 7
                              Sorry, then I misunderstood your question.
                              --
                              Rob

                              ___________
                              Rob Dillon
                              Adobe Community Expert
                              http://www.ddg-designs.com
                              412.243.9119
                              • 12. Re: actionscript help
                                raminu Level 1
                                finaly it's works
                                The problem was very simple.
                                I just use in my php file:
                                & in front of "litere" and run perfectly.
                                Thank's for those who answered ,most GWD :)