7 Replies Latest reply on Mar 28, 2008 10:30 AM by Greg Dove

    Using XML and Arrays

    ndisdabest
      Hi all --

      I'm trying to load some XML data into three separate arrays -- I'm pretty sure that's working. However, I get "undefined" when I try to trace, and I can't assign a specific item (i.e. "swf_url[1]") to a variable. Could someone take a look at this code -- what exactly am I doing wrong?

      Thanks in advance!
        • 1. Re: Using XML and Arrays
          Greg Dove Level 4
          Its actually pretty hard to let people know what's going on with XML without seeing an example of the XML itself sometimes. But I can't figure out what you're trying to do with the loops there...I don't *think* you need 2 for what you're doing...if I understand correctly what you want to do... here's my guess (something like this):

          • 2. Re: Using XML and Arrays
            Greg Dove Level 4
            Do you mean that the traces inside bannerInfo.onLoad trace 'undefined' ?
            • 3. Re: Using XML and Arrays
              ndisdabest Level 1
              GWD --

              Thanks for your help and my apologies for a confusing post. Let me clarify a bit and show you some of my XML.

              I am building a banner rotator -- something that will give the web producers at my office the ability to edit an XML file and add a new Flash banner without having to touch any code. I need to capture 3 or 4 attributes in each XML entry: "swf_url", "click_url", "descrption", and maybe "id" at some point. You'll see in my XML example why the two loops are needed. (I'm also experimenting with an XML file that doesn't nest as many tags and that I could probably call in using ".attributes" in Flash. I'll attach that as well.)

              I guess I'm just trying to figure out how to use this information once I pull it into an array since I'll need to extract it make this project work. Obviously, this isn't very difficult for a more advance programmer -- I'm guessing I have some sort of scoping issue going on, but I'm not knowledgable enough with arrays to pinpoint the problem.

              Here's some of my code that might give you a better understanding. Any tips or suggestions for better ways to build this would be very much appreciated!

              • 4. Re: Using XML and Arrays
                Greg Dove Level 4
                Well the code I posted will work for your first example, then - you don't need the 2 loops.

                Try it like this and see.
                • 5. Re: Using XML and Arrays
                  Greg Dove Level 4
                  Of course, you can't do anything with those arrays until after bannerInfo.onLoad has executed... so if you want to use the loaded values you need to call a function or goto a frame that uses them after those trace actions.
                  • 6. Re: Using XML and Arrays
                    ndisdabest Level 1
                    Very cool. Thanks for your help.

                    Aren't I already launching bannerInfo.onLoad in the function?
                    • 7. Re: Using XML and Arrays
                      Greg Dove Level 4
                      And here's a rough sketch of changes to make the attributes version work.
                      You're putting objects in a single array there, so tracing the element would trace as [object Object] or similar. I've changed the trace to the individual properties of each newly inserted array element.
                      -untested, but I think its right-