9 Replies Latest reply on Jul 21, 2010 1:56 PM by GumpsterF

    Accessing the root

    GumpsterF

      Hi.

      I have a XML reader script, that works great when running on the root level of my flash file.

       

      The actionscript is set to create copies of a movieclip called banstead which consists of a background and a dynamic text field.

      You place one instance of the movieclip (instance named "banstead") on the stage.

      It then populates (in this case 5) instances of a name, target and href for each button from an xml file called "counties.xml" when the movie is run.

      Everything workds just fine including the click through URL's.

       

      here is the actionscript;

       

      weblinkXML = new XML();
      weblinkXML.ignoreWhite = true;
      weblinkXML.load("counties.xml");
      weblinkXML.onLoad = function(success) {
          trace("success = "+success);
          banstead._visible=FALSE;// hide the original button: we're making copies
          for (var i:Number = 0; i< weblinkXML.childNodes.length; i++) {
              var myName:String = weblinkXML.childNodes[i].attributes.buttonName;
              // make sure banstead is a MovieClip, not a button, otherwise duplicateMovieClip won't work!
              var myButton:MovieClip = banstead.duplicateMovieClip(myName, i+1);
              // I've assumed your button has a dynamic text field in it named buttonLabel:
              myButton.buttonLabel.text=myName;
              myButton._y=banstead._y+ i*(banstead._height+5);// position the new button
              myButton.href = weblinkXML.childNodes[i].attributes.href;
              myButton.onRelease = function() {
                  getURL(this.href);// note that each button has it's own href variable
              };
          }
      };
      

       

      here is the xml;

      <?xml version="1.0" encoding="utf-8"?>
      <button buttonName="Joe Blow" targ="_blank" href="http://www.marca.com"> </button>
      <button buttonName="Alderman 2" targ="_self" href="http://www.yahoo.com"> </button>
      <button buttonName="Alderman 3" targ="_self" href="http://www.google.com"> </button>
      <button buttonName="Alderman 4" targ="_self" href="http://www.google.com"> </button>
      <button buttonName="Alderman 5" targ="_self" href="http://www.google.com"> </button>
      

       

      Now I have placed the banstead movieclip into another movieclip called "ward2", with the actionscript.

       

      It still creates the 5 copies and populates the names OK, but the click through URL's do not work. The script creates a button called myButton. The myButton.onRelease does not work when placed inside the ward2 Movieclip.

       

      I just assumed that if I prefaced the code witha _root, it woiuld allow the buttonto be access at the root level, but it does not.

       

      Can anyone tell me how I can get the myButton url function to work inside the ward2 mc?

       

      Thanks

      Forrest

        • 1. Re: Accessing the root
          kglad Adobe Community Professional & MVP

          if banstead is on the _root timeline, use:

           


           

           

          weblinkXML = new XML();
          weblinkXML.ignoreWhite = true;
          weblinkXML.load("counties.xml");
          weblinkXML.onLoad = function(success) {
              trace("success = "+success);
              banstead._visible=FALSE;// hide the original button: we're making copies
              for (var i:Number = 0; i< weblinkXML.childNodes.length; i++) {
                  var myName:String = weblinkXML.childNodes[i].attributes.buttonName;
                  // make sure banstead is a MovieClip, not a button, otherwise duplicateMovieClip won't work!
                  var myButton:MovieClip = _root.banstead.duplicateMovieClip(myName, i+1);
                  // I've assumed your button has a dynamic text field in it named buttonLabel:
                  myButton.buttonLabel.text=myName;
                  myButton._y=banstead._y+ i*(banstead._height+5);// position the new button
                  myButton.href = weblinkXML.childNodes[i].attributes.href;
                  myButton.onRelease = function() {
                      getURL(this.href);// note that each button has it's own href variable
                  };
              }
          };

           


          • 2. Re: Accessing the root
            Ned Murphy Adobe Community Professional & MVP

            If I recreate what you described the code and buttons work fine.  Did you assign mouse/button code the ward2 clip?

            • 3. Re: Accessing the root
              GumpsterF Level 1

              Thanksfor the Feedback KGlad and Ned.

              Once again I have not done a good job at explaining my problem.

               

              KGlad, your fix doesn't help me because the banstead mc is not at the root level, it is inside the ward2 mc. What I am trying to do is have this function;

              myButton.onRelease = function() {
                          getURL(this.href);// note that each button has it's own href variable
                      };
              

              work when the movie is run. Right now when you trace the this you get nothing on mouse release, I think because it is inside another mc. I was wondering if there was a way to code it so that function would work at the root level.

               

              Ned, I am not sure what you mean by assigning button code the ward2 clip. The as2 is written in the timeline inside the ward2 clip.

               

              Here is a link to a zip file that contains the xml and flash file. I think you will see what I mean easier by looking at the file.

              http://www.calgaryheraldonline.com/services/adobe-forums/files4adobeforums.zip

               

              Forrest

              • 4. Re: Accessing the root
                kglad Adobe Community Professional & MVP

                then use:

                 


                 


                 

                 

                weblinkXML = new XML();
                weblinkXML.ignoreWhite = true;
                weblinkXML.load("counties.xml");
                weblinkXML.onLoad = function(success) {
                    trace("success = "+success);
                    banstead._visible=FALSE;// hide the original button: we're making copies
                    for (var i:Number = 0; i< weblinkXML.childNodes.length; i++) {
                        var myName:String = weblinkXML.childNodes[i].attributes.buttonName;
                        // make sure banstead is a MovieClip, not a button, otherwise duplicateMovieClip won't work!
                        var myButton:MovieClip = ward2.banstead.duplicateMovieClip(myName, i+1);
                        // I've assumed your button has a dynamic text field in it named buttonLabel:
                        myButton.buttonLabel.text=myName;
                        myButton._y=banstead._y+ i*(banstead._height+5);// position the new button
                        myButton.href = weblinkXML.childNodes[i].attributes.href;
                        myButton.onRelease = function() {
                            getURL(this.href);// note that each button has it's own href variable
                        };
                    }
                };

                 


                • 5. Re: Accessing the root
                  GumpsterF Level 1

                  Nope. Now the duplicate function and the xml feed is not working at all.

                  Forrest

                  • 6. Re: Accessing the root
                    kglad Adobe Community Professional & MVP

                    then banstead's not a child of ward2 or ward2 is out of your current scope.

                     

                    what's the following trace() show:

                     



                     


                     

                     

                    weblinkXML = new XML();
                    weblinkXML.ignoreWhite = true;
                    weblinkXML.load("counties.xml");
                    weblinkXML.onLoad = function(success) {
                        trace("success = "+success);
                        banstead._visible=FALSE;// hide the original button: we're making copies
                        for (var i:Number = 0; i< weblinkXML.childNodes.length; i++) {
                            var myName:String = weblinkXML.childNodes[i].attributes.buttonName;
                            // make sure banstead is a MovieClip, not a button, otherwise duplicateMovieClip won't work!
                    trace(ward2+":"+ward2.banstead);       
                    var myButton:MovieClip = ward2.banstead.duplicateMovieClip(myName, i+1);

                            // I've assumed your button has a dynamic text field in it named buttonLabel:
                            myButton.buttonLabel.text=myName;
                            myButton._y=banstead._y+ i*(banstead._height+5);// position the new button
                            myButton.href = weblinkXML.childNodes[i].attributes.href;
                            myButton.onRelease = function() {
                                getURL(this.href);// note that each button has it's own href variable
                            };
                        }
                    };

                     


                    • 7. Re: Accessing the root
                      GumpsterF Level 1

                      I get;

                       

                      undefined:undefined

                      undefined:undefined

                      undefined:undefined

                      undefined:undefined

                      undefined:undefined

                       

                      Were you able to download the files I posted?

                       

                      Banstead is the instance name of a movieclip placed inside a Movieclip with an instance name of ward2.

                      The actionscript is in the ward2 timeline. It makes the banstead mc invisible and them makes as many duplicates as it needs from the number of nodes coming in from the XML file. It places these duplicates inside the ward2 movieclip when the movie is run.

                       

                      It is just that the myButton href function will not work because you cannot click on the buttons that are created inside the ward2 movieclip.

                       

                      Forrest

                      • 8. Re: Accessing the root
                        Ned Murphy Adobe Community Professional & MVP

                        The problem is as I alluded to before.  ward2 has rollover code assigned to it.  This will block any mouse interaction with objects inside ward2.

                        • 9. Re: Accessing the root
                          GumpsterF Level 1

                          You are bang on Ned.

                          Sorry, I was not understanding your first note.

                          Yes, when I take off that rollover code the click through's work excellent.

                          I just have to figure out a way to get the roll over to move the timeline along other than coding the mc.

                          Thanks,

                          Forrest

                           

                          ps, if either of your fellows want to take a stab at explaining to me how to write the xml and as2 code to also incorporate a image into the button, I would appreciate it, but not to worry..