5 Replies Latest reply on Aug 31, 2012 9:22 AM by kglad

    Problem with loading xml (outside variable issue)

    Shohag_ifas

      hi, Greetings to everyone on this forum..

       

      i m very newbie to flash/AS2.. i need to load xml file so, i search Google and found this link:

      http://www.republicofcode.com/tutorials/flash/xml/

       

      and i am using the following code:

      var myXML:XML = new XML();

      myXML.ignoreWhite=true;

      myXML.load("oman3d.xml");

      myXML.onLoad = function(success)

      {

          if (success)

          {

              //trace (myXML);

              var imageLink1 = myXML.firstChild.childNodes[2].firstChild.nodeValue;

              trace (imageLink1);

       

          }

      }

       

      trace(imageLink1);

       

      Stop();

       

      but there is the problem, here is the output:

      undefined

      image3.jpg

       

      as you may noticed i need to use that variable outside of that success function.. as i need to use that variable some where else

       

      but when i try to use that variable outside,it says undefined

       

      i hope some one can help me out on this issue

       

      best regards

        • 1. Re: Problem with loading xml (outside variable issue)
          esdebon Level 4

          var myXML:XML = new XML();

          var imageLink1="";

          myXML.ignoreWhite=true;

          myXML.load("oman3d.xml");

          myXML.onLoad = function(success)

          {

              if (success)

              {

                  //trace (myXML);

                  imageLink1 = myXML.firstChild.childNodes[2].firstChild.nodeValue;

                  trace (imageLink1);

              }

          }

           

           

          trace(imageLink1);

           

           

          Stop();

          1 person found this helpful
          • 2. Re: Problem with loading xml (outside variable issue)
            Shohag_ifas Level 1

            dear "esdebon" sir, thanks for your reply.. but that didn't work..

             

            anyone else please?

            • 3. Re: Problem with loading xml (outside variable issue)
              kglad Adobe Community Professional & MVP

              you're tracing imageLink1 before it's defined in your onLoad method.  even though that 2nd trace appears after the trace in onLoade, it executes before that trace.

               

              p.s.  you still need to use estebon's suggestion because you were making imageLink1 local to onLoad by declaring it inside that function.  actually, it would be better to use:

               

              var imageLink1:String

               

              outside onLoad.

              1 person found this helpful
              • 4. Re: Problem with loading xml (outside variable issue)
                Shohag_ifas Level 1

                dear sir kglad, that didn't work too

                 

                even i put that var imageLink1:String on top of others code..

                 

                but that still doesn't work

                 

                any help ?

                • 5. Re: Problem with loading xml (outside variable issue)
                  kglad Adobe Community Professional & MVP

                  you're not reading carefully.   just copy and paste the following, read the output and study the code to understand what's been explained.

                   

                  var imageLink1:String;

                  var myXML:XML = new XML();

                  myXML.ignoreWhite=true;

                  myXML.load("oman3d.xml");

                  myXML.onLoad = function(success)

                  {

                      if (success)

                      {

                          //trace (myXML);

                          var imageLink1 = myXML.firstChild.childNodes[2].firstChild.nodeValue;

                          trace ("this works and appears on the 2nd line of output: "+imageLink1);

                  traceF();

                      }

                  }

                   

                  trace("this outputs before imageLink1 is defined so you expect this to be on the first line and undefined = "+imageLink1);

                   

                  function traceF():Void{

                  trace("this is the 3rd and last line of output and will show imageLink1 is defined outside onLoad.  imageLink1 = "+imageLink1);

                  }

                   

                   

                   

                  p.s.  please mark helpful/correct responses.

                  1 person found this helpful