2 Replies Latest reply on Oct 21, 2009 5:13 AM by Ned Murphy

    Variable scope access????

    dc2698
      My code:

       

      Code:
      onClipEvent (construct)
      {
           function isLoaded(success)
           {
                if (!success)
                {
                     return (0);
                } // end if
                objArray = new Array();
                var pic = this.firstChild.attributes.pic;
                objArray.push(pic);
                                trace(objArray[0]);  // NO PROBLEM!!!
           } // End of the function
           var xmlDoc = new XML();
           xmlDoc.ignoreWhite = true;
           xmlDoc.onLoad = isLoaded;
           xmlDoc.load("pic.xml");
           trace(objArray[0]);  // UNDEFINED!?!?!?!?!?!??!?!?!?
          img_source = pic;  // BIG PROBLEM
      }
      My pic.xml is just <?xml version="1.0" encoding="utf-8" standalone="yes" ?><items pic="img01.jpg"></items>

       

      What made me mad is that, objArray[0] can be accessed only in the isLoaded(). When trying to access it outside isLoaded() then it failed.

       

      Please help me out thanks in advance!
        • 1. Re: Variable scope access????
          carlaguggino

          have you tried doing it this way?

           

          obj=new Array;
          obj.push(...) ;
          trace(obj);
          return obj;

           

          Good luck

          Carla Guggino

          Mi tienda informatica

          • 2. Re: Variable scope access????
            Ned Murphy Adobe Community Professional & MVP

            Where you say the objArray is UNDEFINED it is undefined.  Those lines of code process faster than the loading of the file--they don't wait for it to finish first.  You do not want to do anything with the data being loaded until the loading is complete, which occurs in the function.

             

            Also, where do you actually declare the objArray variable (var objArray;) ?

             

            If you were to declare it inside that function, it would only have scope within that function

            1 person found this helpful