10 Replies Latest reply on Jan 4, 2011 5:11 PM by kglad

    Problem with If Statement


      Well, my first post here, hope i can solve this =)


      The problem is that i do have a if that seems to not obey me:


      if (_parent.foto2 == 'no' ) {

      btNext._visible = false;



      I believe I am having some problem with the variable "foto2". I  tried tracing, and if I add a 'trace ('_parent.foto2') right before the if, the result is 'no'.

      So i'm 100% that what's inside the var on the moment of the loop is 'no'. I can even use it to change dynamic text boxes to 'no'.

      What maybe possible is that it's a type of var that if  doesn't understand maybe?

      So i'll try to be short explaining from it comes.


      I'm doing a gallery where a click on a thumbnail leads to a zoom image, or images, based on XML, so firstly I prepared a set of vars from the xml:


      function checkLoading(success) {

      if (success == true) {

      var totalNodes = imagesXML.firstChild.childNodes.length;


      for (i=0; i< totalNodes; i++){

      fotoEnd = 'images/lookbook/' + imagesXML.firstChild.childNodes[i].firstChild.firstChild;

      this["fotoToLoad"+i] = fotoEnd;

      this["fototwo"+i] = imagesXML.firstChild.childNodes[i].childNodes[1].firstChild;

      this["text"+i] = imagesXML.firstChild.childNodes[i].childNodes[2].firstChild;



      frame1.loadFirst (this);




      The last function there, loadFirst, runs inside the thumbnail, it it uses fotoToLoad+i as the thumb to load (and also the first zoom image), fototwo+i as the second image of zoom (wich might be an image filename or a 'no', wich i would use as control to showor not the brNext button). And the text+i is the images's description. I'm also forwarding the this to the function so that i can use the vars there.



      On the thumbnail mc I have a moviecliploader working, so that it will fun the followin after load ends:


      foto25 = varHold.fototwo1;
      Varhold is the forwarded this. I'm setting it the values to a var there because I want to leave it avaible inside the thumbnail, for when the user clicks it a function will load the first image and, onLoadInit, forward those vallues to a variable in _root, this way I can do one zoom mc that checks always the same vars on root.
      So when the thumb is finally clicked, there's a moviecliploader to load the first big image, and onLoadInit it runs this:
      _parent._parent.foto2 = foto25 ;
      _parent._parent.texto = texto;
      Creating finally the var i use in the if that is giving me the trouble.
      I just don't know what i did not do, but the var is just un-usable for the if statement, even thou I can use it's values to load images, output text, do traces and such. =(
      Thanks in advance to whom read this, for I'm already gettin a bit nuts since i've been checking this over and over for the last 4/5 hours -.-.

        • 1. Re: Problem with If Statement
          kglad Adobe Community Professional & MVP

          check for whitespace:


          trace(_parent.foto2+" "+_parent.foto2.length);

          if (_parent.foto2 == 'no' ) {


          btNext._visible = false;


          1 person found this helpful
          • 2. Re: Problem with If Statement

            Thank you, I guess the result was rather "intersting".... the lenght resulted in "undefined":




            no undefined




            • 3. Re: Problem with If Statement
              kglad Adobe Community Professional & MVP

              so, that means _root.foto2 is NOT a string (if your spelled length correctly in your code).  did you and if so, what data type is it?

              • 4. Re: Problem with If Statement
                vbkun Level 1

                Yes i fixed it!


                That's the thing i suspected, that it wasn't a string (that why i told the variable life up there ^_^ ).


                I'm not sure when/where it left being a string (or even if it ever was). =(

                • 5. Re: Problem with If Statement
                  vbkun Level 1

                  The thing is, I know how to set a var type like this:


                  Var Myvar:String = "string";


                  But the only way i managed to find to create vars inside a loop was:


                  this["fototwo"+i] = imagesXML.firstChild.childNodes[i].childNodes[1].firstChild;


                  I just checked and the other vars created there were also not Strings.


                  Or maybe the fact that, to use the vars in next function i forwarded it like this:


                  frame1.loadFirst (this);


                  cause them to leave being Strings?

                  • 6. Re: Problem with If Statement
                    vb_k Level 1

                    I just did some futher testing,


                    I changed : this["fototwo"+i] = imagesXML.firstChild.childNodes[i].childNodes[1].firstChild;

                    for : _root["fototwo"+i] = imagesXML.firstChild.childNodes[i].childNodes[1].firstChild;


                    So that i could check the vars without all the forwarding, the result when i asked to trace the length was undefinied, so any tips of how to make that generate Strings and not what it is generating?

                    • 7. Solved, not in a perfect way thou
                      vb_k Level 1

                      I appended the adress to the filename... so that would for the recognition as string...

                      Like this:


                      fotoEnd2 = 'images/lookbook/' + imagesXML.firstChild.childNodes[i].childNodes[1].firstChild;

                      this["fototwo"+i] = fotoEnd2;


                      not a perfect solution but will do...


                      If anyone can help me on point how to create a string in the case in a better way... without appending extras >_< I'm thankfull =)

                      • 8. Re: Solved, not in a perfect way thou
                        kglad Adobe Community Professional & MVP

                        1.  xml values are strings.

                        2.  it's not clear you're using an xml value.  that's probably an xmllist object.  you can use the toString() method of xmllist objects to convert to a string.

                        3.  you can't "type" a dynamic variable like this["fototwo"+i].

                        1 person found this helpful
                        • 9. Re: Solved, not in a perfect way thou
                          vb_k Level 1



                          Thanks again for the reply.


                          How I've set the xml load -> var imagesXML = new XML();


                          So i guess this was the real issue then.


                          Side question, what would be the best way to type a dynamic var inside a loop? The only method i found for creating vars in that condition was the this["myvar"+i]. -.-



                          Thanks again!

                          • 10. Re: Solved, not in a perfect way thou
                            kglad Adobe Community Professional & MVP

                            you can't type a dynamic variable.

                            1 person found this helpful