Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Problem with pushing xml child attribute to an empty array

New Here ,
Oct 19, 2013 Oct 19, 2013

Hi guys,

I have another problem with putting, or shall I say, pushing data from xml to an empty array I previously declared.

During the xml_mc.onload, I can see the data, but after that, it becomes undefined.

It seems like I could not find the solution on the net as well. I suspect it is not possible, but I wont give up.

Please help me.

Thanks.

This is the code sample:

var myarray=new Array();

var xml1:XML = new XML();

xml1.ignoreWhite=true;

xml1.onLoad = function(success:Boolean){

          if(success){

      var nodes = this.firstChild.childNodes;

      

                    for (i=0; i<nodes.length; i++){

               myarray=nodes.attributes.name;

                    }

 

         text1.text=myarray[2];  // *******************************to check if the attribute "name" is visible

 

          } else {

                    trace("Could not load XML");

          }

}

xml1.load("icons.xml");

text1.text=myarray[2]; // *******************************I commented the first  text to try to view again, and result was UNDEFINED..........

the xml would look like this:

icons.xml

<icons>

     <icon name="icon1" />

     <icon name="icon2" />

     <icon name="icon3" />

     <icon name="icon4" />

</icons>

thanks

TOPICS
ActionScript
679
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

LEGEND , Oct 19, 2013 Oct 19, 2013

I don't understand your problem.  The array does fill with the data.  If you are expecting that second "text1.text = " to show anything but "undefined" it is not going to happen as you have it written.  That line of code executes before the onLoad function does  (code execution does not wait for files to load).  You only want to deal with processing the data after the onLoad function has processed it into the array.

Translate
LEGEND ,
Oct 19, 2013 Oct 19, 2013

I don't understand your problem.  The array does fill with the data.  If you are expecting that second "text1.text = " to show anything but "undefined" it is not going to happen as you have it written.  That line of code executes before the onLoad function does  (code execution does not wait for files to load).  You only want to deal with processing the data after the onLoad function has processed it into the array.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Oct 19, 2013 Oct 19, 2013

Hi Ned,

Yes...I now get your point. I have not realized before what you just said...

And it is working now.

Thank you always.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Oct 20, 2013 Oct 20, 2013
LATEST

You're welcome

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines