6 Replies Latest reply on Jun 4, 2008 1:25 PM by Christopher Barnard

    XML and an array to call attachMovie

    Christopher Barnard
      As my slideshow moves through my nodes I want to be able to call attachMovie and place a MC on the stage. I have got this far:

      function parse():Void {
      if (xmlData.firstChild.nodeName == "girls") {
      var rootNode:XMLNode = xmlData.firstChild;
      }
      for (i=0; i<rootNode.childNodes.length; i++)

      myArray.push(rootNode.childNodes .nodeName);
      }

      trace(myArray.length);

      if (myArray [x])

      {_this.attachMovie("mcgirl1", "girl_mc", this.getNextHighestDepth(), {_x:Stage.width / 2, _y:Stage.height / 2});

      }

      The last part of the code from "if" is nonsense but I hope it suitably demonstrates what I'm trying to do. I want the actionscript to follow which node of the xml I'm in and then complete a function.

      I have got confused because I see the XML as array, but I have to 'push' that array onto another array to acheive some output?

      If anyone can help I'd be very happy.

      Chris
        • 1. Re: XML and an array to call attachMovie
          clbeech Level 3
          well this seems an odd question but ... if you have all of the images within the file, why are you using xml?

          you could just place the image linkage names within the array, and then use a method to attach them to the Stage when the 'next' or 'back' buttons are pressed (I think that's what your trying to do) or on an interval timer.

          is that kind of what you're looking for?
          • 2. Re: XML and an array to call attachMovie
            Christopher Barnard Level 1
            Thanks for the super speedy response!

            No, all the images are external. Therein lies the problem otherwise I admit it would be simpler. There are a few images and I wanted to use XML for obvious reasons - update pictures, movie size - usual stuff.

            The slide show changes automatically and has the usual backwards and forwards buttons.

            I thought I could do something simple like 'if (childNodes.nodeName = something)'...

            But I'm looking at setting up another array to store the XML details and which point I've got lost.

            Any pointers greatly appreciated!





            • 3. Re: XML and an array to call attachMovie
              clbeech Level 3
              ok - what you need to do here is to 'iterate' through the xml return, and gather the address to the files. you will not be able to use the attachMovie method, you will need to use the MovieClipLoader class to load the external images into MCs that you create dynamically. you can do much of this within the xml onLoad handler. just for starters...
              • 4. Re: XML and an array to call attachMovie
                Christopher Barnard Level 1
                I really appreciate that...fantastic,

                but if I've got it right isn't the code just rendering my images dynamically now as movie clips on the stage - what I want to do is attach new animations to the stage based on which slide I'm displaying in my movie from the XML.

                You must forgive me if this is what the script is doing, but to my untrained eyes it looks like it's assigning each slide (each image) as an MC.



                • 5. Re: XML and an array to call attachMovie
                  clbeech Level 3
                  very good, you are correct that's exactly what it's doing, as well as 'centering' the images on an open stage. what you can do then is target a movieclip instance to load the dynamic instances into (just like what it's doing but in another container you can control to positioning of) and then if you wish to attach a MC from the Lib use the runShow() method to do so and the 'index' value to pull the corresponding clip.

                  to do so, create another array and type in the linkage identifier name of the clips from the Lib in the order that corresponds to the images being loaded. now if you want to use the XML doc to 'store' the list of MCs to call in another node or attribute, you could do that too - you would then just need to add another element to the load loop in the onLoad handler, get the value from the correct node, and push it into a different array.
                  • 6. Re: XML and an array to call attachMovie
                    Christopher Barnard Level 1
                    I understand the need to create the array with the movieclip identifiers - that makes sense, but what am I pulling from the existing code to trigger this - what part of the code monitors the iteration through the XML - put it in laymens terms I don't understand how to 'link' the two processes.

                    Do I have to create an if/else statement as part of the runShow () function. How does flash know which node of the XML tree I'm on in order to pull the correct movie from the library ? We can load in the images but how does flash know which image is which.

                    Is it just done sequentially through the for loop?

                    As you can see I'm guessing just a little bit. Any further help aapreciated - if you have pointers to go back to some basics to see what I'm missing let me know.

                    Also at the moment I might find it tricky to incorporate this into my existing code - but I'll work with yours until I'm pulling the movies from the library!

                    Thanks again...

                    Chris