create incrementing variables in functions

  • Havoc
  • Born
  • Born
  • User avatar
  • Posts: 1
  • Loc: Ottawa, Canada

Post 3+ Months Ago

I am using Flash MX (ver 6.0)

I have a list of info that will be posted in an xml file that will be updated often. I have the xml coming in fine and everything seems ok on that part.

I am trying to increment a variable name + number and the assign it the next value of the the childNodes.

ok here is an example of what i mean since that is probably hard to understand. This is part of the script i have for getting loading the xml. you will where i am using a for loop to work through the nodes in my xml file.
Code: [ Select ]
        my_xml = new XML();
        my_xml.ignoreWhite = true;
        my_xml.load('test.xml');
        my_xml.onLoad = function(success) {
            if (success) {
                    for(t=0;t<=my__xml.firstChild.childNodes.length;t++){
                        if(my_xml.firstChild.childNodes[t].nodeName == "name"){
                        // is this next line correct? if so how do i access it outside the function?
                            _root["list"+t] = my_xml.firstChild.childNodes[t].firstChild.nodeValue;
                            }
                        }
                    }
            }
  1.         my_xml = new XML();
  2.         my_xml.ignoreWhite = true;
  3.         my_xml.load('test.xml');
  4.         my_xml.onLoad = function(success) {
  5.             if (success) {
  6.                     for(t=0;t<=my__xml.firstChild.childNodes.length;t++){
  7.                         if(my_xml.firstChild.childNodes[t].nodeName == "name"){
  8.                         // is this next line correct? if so how do i access it outside the function?
  9.                             _root["list"+t] = my_xml.firstChild.childNodes[t].firstChild.nodeValue;
  10.                             }
  11.                         }
  12.                     }
  13.             }

ALSO, how to I access the information stored in the newly created "list" variable? Everything I have tried fails.
I seem to be able to access variables created in the main timeline inside functions no problem, but can not access variables created in the function in the main timeline.

In case you want to see the xml file this is the test i was using to work this out.
Code: [ Select ]
<?xml version="1.0" encoding="iso-8859-1"?>
<people>
        <name>Zach</name>
        <name>Gavin</name>
</people >
  1. <?xml version="1.0" encoding="iso-8859-1"?>
  2. <people>
  3.         <name>Zach</name>
  4.         <name>Gavin</name>
  5. </people >

I have used Flash off and on for years but just started to dive into actionscript and XML is new ground as well.
As far as knowing any scripting languages I have done ASP in the past and switched to PHP a couple years ago.


Thanks for any help you can give me.
:)[quote][/quote]
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • joebert
  • Fart Bubbles
  • Genius
  • User avatar
  • Posts: 13503
  • Loc: Florida

Post 3+ Months Ago

Notice anything different in theese two lines ?
Code: [ Select ]
for(t=0;t<=my__xml.firstChild.childNodes.length;t++){

Code: [ Select ]
_root["list"+t] = my_xml.firstChild.childNodes[t].firstChild.nodeValue;

There's an extra underscore in the first lines xmlObj.
  • joebert
  • Fart Bubbles
  • Genius
  • User avatar
  • Posts: 13503
  • Loc: Florida

Post 3+ Months Ago

Since the onLoad puts you in the scope of the xmlObj you can replace both of them with this to reduce(or in some cases increase) confusion :)
  • uknightuss
  • Graduate
  • Graduate
  • uknightuss
  • Posts: 196
  • Loc: Los Angeles

Post 3+ Months Ago

Good Eye!

Post Information

  • Total Posts in this topic: 4 posts
  • Users browsing this forum: No registered users and 12 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.