9 Replies Latest reply on Apr 16, 2007 1:46 PM by Optikalefx

    Weird results evaluating variable

    GraphicsGeezer Level 1
      I know my SWF file is recognizing variables from a remote file, but I can't get Action Script to do anything based on their values.

      Here's what's happening: I have a questionnaire with several pages in HTML. Using PHP I can write variables to a text file. I've figured out how to get the variables into the SWF file and I've placed dynamic text boxes in the file so that I know the variables are being recognized. For example, when a user completes "Part A" of the questionnaire, a dynamic text box for Part A shows the value "a".

      So you'd think if I just wrote a script saying if the variable equals "a" then a movie should have its alpha set to 100, or:
      if(parta=="a"){
      setProperty(this.partacheckbox, _alpha, 100);
      }
      But for the life of me I can't get it to work.

      I've tried everything I can think of including initializing the variable with: var parta:String = "x"; but I can't seem to get anywhere.

      I've done this sort of thing elsewhere in the file and I'm using exactly the same action script, but no success. I've tried changing variable names in cas that interferes, but still no success.

      I've spend six hours trying to get this to work and would be glad to pay for a solution except the job I'm doing is voluntary.

      Thanks for any help.

        • 1. Re: Weird results evaluating variable
          kglad Adobe Community Professional & MVP
          timing is important. you can't cehck if parta="a", until the data have been received.
          • 2. Re: Weird results evaluating variable
            Rothrock Level 5
            You are doing this test repeatedly, right? Otherwise the most likely reason is that the textfield doesn't equal to "a" the one time you check, but rather a moment or two later. Other than that its hard to know, but you can start with:

            if(parta.text=="a"){
            trace("the textfield says a");
            this.partacheckbox._alpha=100;
            }

            That is of course assuming that the text field is in a scope that this is seeing. I've also put a trace in there. It is possible that the if is evaluating to true and that you aren't correctly scoping partacheckbox.
            • 3. Re: Weird results evaluating variable
              GraphicsGeezer Level 1
              I don't know about timing but it should be okay. The flash movie is only one frame long and the dynamic text field says the variable equals 'a'. Since the web site is in PHP and I don't have PHP on my computer I have to put the file on line to check. You can't get the trace() function to work then, right?

              Also, what do you mean by scope?

              • 4. Re: Weird results evaluating variable
                kglad Adobe Community Professional & MVP
                you think the timing "...should be ok"?? and why is that?

                hint: the timing is almost certainly the issue.
                • 5. Re: Weird results evaluating variable
                  Rothrock Level 5
                  Actually the problem is most likely that the timing isn't okay.

                  Scope means the timeline that variables and/or objects are defined on. Let's say that you have two movieclips on the stage clipA and clipB. Inside of each one is a text field called myLabel. From some code on the main timeline how would Flash or you know which one you meant by this

                  trace("The label is "+myLabel.text);

                  Scope comes to the rescue! Instead of the above you would say:

                  trace("The label in clipA is "+clipA.myLabel.text);

                  Scope isn't just for when things have the same names. Flash always needs to know where to look for things. So a lot of problems here on these boards are caused by incorrect scope.

                  The other most popular reason for problems is that people try to assign values or read them before external content has loaded or before movieclips exist on a certain frame. Which is your problem here.
                  • 6. Re: Weird results evaluating variable
                    GraphicsGeezer Level 1
                    Thanks for your help on this earlier. I've returned to the problem, but still don't understand where I'm going wrong. If the dynamic text box displays the variable, why can't an action 'see' the same variable? There is no hierarchy of movie clips involved. It's all one timeline and the movie is only one frame.

                    Thanks

                    • 7. Re: Weird results evaluating variable
                      Rothrock Level 5
                      It is hard to know without seeing the part where you request the info and where you check it. But both kglad and I have been doing this for a loooonnnggg time. Not that it always is the problem, but at least 97 out of 100 times it is. (Of the other 3, 2 are timing plus some other issue!)

                      So how are you talking to the PHP?
                      • 8. Re: Weird results evaluating variable
                        kglad Adobe Community Professional & MVP
                        the textfield's display will change as soon as the variable changes value. there's no timing issue. most everything else depends upon timing.
                        • 9. Re: Weird results evaluating variable
                          Optikalefx Level 1
                          Heres your problem, timing is the answer.

                          Your trying to use the variables before they are there. The dynamic text boxes work because they actually just sit there till the data is loaded. However in actionscript its undefined because its all being run in a milisecond and it takes someeimes 1 or 2 seconds to recieve the data. so heres what I do. Make a variable in the text file &ToF=true

                          and in flash make this boolean

                          keepDoing = setInterval(doThis,1); //in order to repeat the if statement ( i never go while to work)
                          function doThis() {
                          this.loadVariables("url","POST"); //load variables
                          if (this.ToF == true) { //its false right now, when its true then we know the variables are loaded
                          clearInterval(keepDoing); //make sure it doesnt keep loading over and over

                          //code goes here

                          }// end if
                          }// end function

                          thi