5 Replies Latest reply on Jun 15, 2009 7:29 AM by kglad

    Loading/unLoading XML data

    Graphic Graeme Level 1

      Hello,

       

      I have an accordion style btn that expands and contracts base on the user's cursor.

      When the btn expands it loads an external XML file. The problem I'm having is that after the

      btn contracts the loaded XML content is still in place. Is there a way to unload this XML content after it has loaded?

       

      Cheers-

      Graeme

        • 1. Re: Loading/unLoading XML data
          kglad Adobe Community Professional & MVP

          you can null the xml instance that was used to load the data.

          • 2. Re: Loading/unLoading XML data
            Graphic Graeme Level 1

            I've attached my code,

            What code would I need to use to Null that instance?

             

            CODE:

             

            stop();

             

            function loadXML(loadedX) {
                if (loadedX) {
                    xmlNode = this.firstChild;
                    image = [];
                    total = xmlNode.childNodes.length;
                for (i=0; i<total; i++) {
                    image[i] = xmlNode.childNodes[i].childNodes[0].firstChild.nodeValue;
                }
                    load_pic();
                } else {
                    content = "file not loaded!";
                }
            }

             

            xmlData = new XML();
            xmlData.ignoreWhite = true;
            xmlData.onLoad = loadXML;
            xmlData.load("images.xml");

             

            function load_pic(){
                k = Math.floor(Math.random()*total);
                picture_1.holder.loadMovie(image[k], 1);
            }

             

            //Store Button Position
            var yPosition:Number = 210;
            var xPosition:Number = 110;

             


            //Declare New XML Object
            var myXML:XML = new XML();
            //Set Flash to ignore the XML file's white space
            myXML.ignoreWhite = true;
            //Declare new Array to store the links from the XML file
            var links:Array = new Array();
            //Declare new Array to store the names from the XML file
            var names:Array = new Array();

             

            //Set XML onLoad function
            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
                    _root.attachMovie("button","btn"+i,_root.getNextHighestDepth());
                    //Set the y position of the buttons
                    _root["btn"+i]._x = xPosition;
                    //Increace the varible yPosition 15 pixel each time the loop runs to place each button under each other
                    xPosition = xPosition+0
                    _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+30;
                    //Place the button name from names Array into the blackTxt text box
                    _root["btn"+(i)].blackTxt.Txt.text = (names[i]);
                    //Place the button name from names Array into the whiteTxt text box
                    _root["btn"+(i)].whiteTxt.Txt.text = (names[i]);
                    //Assign the btnOver function to the button onRollOver state.
                    _root["btn"+(i)].onRollOver = btnOver;
                    //Assign the btnOut function to the button onRollOut state.
                    _root["btn"+(i)].onRollOut = btnOut;
                    //Assign the btnRelease function to the button onRelease state.
                    _root["btn"+(i)].onRelease = btnRelease;
                }
            }
            //Load the XML file
            myXML.load("links.xml");

             

            //Button Over function
            function btnOver(){
                //This referse to the current button the mouse is over
                //Go To And Stop frame 2 of the current button the mouse is over
                this.gotoAndStop(2);
            }
            //Button Out function
            function btnOut(){
                //Go To And Stop frame 3 of the current button the mouse rolls out from
                this.gotoAndStop(3);
            }
            //Button Release function
            function btnRelease(){
                //Set a varible named currentBtn equal to the instance name of the current button the mouse clicked on
                var currentBtn:String = this._name;
                //Set a varible named currentIndex equal to the varible currentBtn and the characters between 3rd letter and 5th of that string.
                //This will return a number between 0 and the total number of buttons
                var currentIndex:String = currentBtn.substring(3,5);
                //Get the URL from the links Array
                //Use the currentIndex varible as the index number
                getURL(links[currentIndex]);
            }

            • 3. Re: Loading/unLoading XML data
              kglad Adobe Community Professional & MVP

              xmlData = null;

              • 4. Re: Loading/unLoading XML data
                Graphic Graeme Level 1

                Thanks Kglad,

                 

                though I'm still not able to get my XMl content to not show up,

                I have posted my btn online at the link below.

                 

                http://www.brandhealth.ca/ATX

                 

                I'll also attach my source

                • 5. Re: Loading/unLoading XML data
                  kglad Adobe Community Professional & MVP

                  the data will no longer be in your xml instance once you null it.  if you've communicated (some of) those data elsewhere and you want to remove that, you'll need to do that.

                   

                  so, for example, if you created movieclips for each node of a particular type and you want to remove those movieclips, you'll need to code to do just that.