create incrementing variables in functions

  • Havoc
  • Born
  • Born
  • User avatar
  • Joined: Sep 20, 2004
  • Posts: 1
  • Loc: Ottawa, Canada
  • Status: Offline

Post September 23rd, 2004, 1:05 am

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
  • Joined: 25 Feb 2008
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post September 23rd, 2004, 1:05 am

  • joebert
  • Sledgehammer
  • Genius
  • No Avatar
  • Joined: Feb 10, 2004
  • Posts: 13455
  • Loc: Florida
  • Status: Offline

Post September 23rd, 2004, 1:50 am

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.
Strong with this one, the sudo is.
  • joebert
  • Sledgehammer
  • Genius
  • No Avatar
  • Joined: Feb 10, 2004
  • Posts: 13455
  • Loc: Florida
  • Status: Offline

Post September 23rd, 2004, 1:52 am

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 :)
Strong with this one, the sudo is.
  • uknightuss
  • Graduate
  • Graduate
  • No Avatar
  • Joined: Sep 15, 2004
  • Posts: 198
  • Loc: Los Angeles
  • Status: Offline

Post September 23rd, 2004, 8:54 am

Good Eye!

Post Information

  • Total Posts in this topic: 4 posts
  • Users browsing this forum: No registered users and 52 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
 
 

© 2011 Unmelted, LLC. Ozzu® is a registered trademark of Unmelted, LLC.