7 Replies Latest reply on Jul 20, 2009 8:45 AM by wwscoper

    placing xml menu items inside a movie clip

    wwscoper Level 1

      Hi all,

       

      I have a basic XML menu that dynamically attaches the menuItem instances to the stage. They are being attached to the root timeline, but I want to put all of the actionscript inside a movieclip called "menu1_mc". I am having some trouble with the proper syntax, because when I move the code inside of the movieclip, I can't get them to attach to the stage unless I still reference _root. I'd like them to attach at (0,0) of the menu1_mc movieclip.

       

      myXML.onLoad = function(){

       

       

      var linkname:Array = this.firstChild.childNodes;

      //Set a for loop

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

       

      //Push the button name into the names Array

      names.push(linkname[i].attributes.NAME);

       

      //Push the button link into the links Array

      links.push(linkname[i].attributes.LINK);

       

      //Attach the button Movie Clip from the libray give it an instance name and place it on the next highest level

       

      _root.attachMovie("button","btn"+i,_root.getNextHighestDepth());

      //Set the y position of the buttons

       

      _root["btn"+(i)]._y = yPosition;

      //Increace the varible yPosition 15 pixel each time the loop runs to place each button under each other

      yPosition = yPosition + 25

       

      //Place the button name from names Array into the blackTxt text box

      _root["btn"+(i)].buttonText.Txt.text = (names[i]);

       

      //Assign the btnRelease function to the button onRelease state.

      _root["btn"+(i)].onRelease = btnRelease;

      }

      }

       

       

      Thanks!

        • 1. Re: placing xml menu items inside a movie clip
          kglad Adobe Community Professional & MVP

          if you want to attach items to the current timeline, use "this" instead of "_root".

          1 person found this helpful
          • 2. Re: placing xml menu items inside a movie clip
            wwscoper Level 1

            I tried that first. Updating the script to this doesn't work.

             

            myXML.onLoad = function(){

            //Set varible to store the XML childNodes

             

            //This allows you to get the number of buttons in the XML file.

            //You'll use this tell flash how many times to loop the for loop.

             

            var linkname:Array = this.firstChild.childNodes;

             

            //Set a for loop

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

             

            //Push the button name into the names Array

            names.push(linkname[i].attributes.NAME);

             

            //Push the button link into the links Array

            links.push(linkname[i].attributes.LINK);

             

            //Attach the button Movie Clip from the libray give it an instance name and place it on the next highest level

            this.attachMovie("button","btn"+i,this.getNextHighestDepth());

             

            //Set the y position of the buttons

            this["btn"+(i)]._y = yPosition;

            //Increace the varible yPosition 15 pixel each time the loop runs to place each button under each other

            yPosition = yPosition + 25

             

            //Place the button name from names Array into the blackTxt text box

            this["btn"+(i)].buttonText.Txt.text = (names[i]);

             

            //Assign the btnRelease function to the button onRelease state.

            this["btn"+(i)].onRelease = btnRelease;

            }

            }

            • 3. Re: placing xml menu items inside a movie clip
              kglad Adobe Community Professional & MVP

              what doesn't work?

              • 4. Re: placing xml menu items inside a movie clip
                wwscoper Level 1

                Hey. I appreciate the replies. I changed "_root" to "this" in my code but the movieclips are no longer dynamically being attached to the stage.

                • 5. Re: placing xml menu items inside a movie clip
                  kglad Adobe Community Professional & MVP

                  use:

                   

                  var tl:MovieClip=this;

                   

                   

                  myXML.onLoad = function(){

                   

                   

                  var linkname:Array = this.firstChild.childNodes;

                  //Set a for loop

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

                   

                  //Push the button name into the names Array

                  names.push(linkname[i].attributes.NAME);

                   

                  //Push the button link into the links Array

                  links.push(linkname[i].attributes.LINK);

                   

                  //Attach the button Movie Clip from the libray give it an instance name and place it on the next highest level

                   

                  tl.attachMovie("button","btn"+i,tl.getNextHighestDepth());

                  //Set the y position of the buttons

                   

                  tl["btn"+(i)]._y = yPosition;

                  //Increace the varible yPosition 15 pixel each time the loop runs to place each button under each other

                  yPosition = yPosition + 25

                   

                  //Place the button name from names Array into the blackTxt text box

                  tl["btn"+(i)].buttonText.Txt.text = (names[i]);

                   

                  //Assign the btnRelease function to the button onRelease state.

                  tl["btn"+(i)].onRelease = btnRelease;

                  }

                  }

                   

                   

                  Thanks!

                  • 6. Re: placing xml menu items inside a movie clip
                    wwscoper Level 1

                    Thanks! This worked.

                    • 7. Re: placing xml menu items inside a movie clip
                      kglad Adobe Community Professional & MVP

                      you're welcome.