5 Replies Latest reply on Dec 3, 2010 3:45 PM by kglad

    use Flash actionscript to load XML file then apply URL links to the item

    wannigan

      Hi all,

       

      I am looking for some help here as I am stuck on the last stage of my flash actionscript project, so if anyone could help me out I will be really grateful as I have been stuck on it for days now.

       

      I have already used actionscript to loaded the xml file which includes names, link, titles, description but for some strange reasons it said it couldn't find the location of the link, so here's my code for teh actionscript:

       

      /****************************************************
      // General XML file loading with button positioning
      ****************************************************/

       

      _root.closeButton._y = -3000;
      _root.closeButton._x = 650;

       

      //Store Button Position
      var xPosition:Number = 0;
      var yPosition:Number = 0;

       

      //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();
      var names:Array = new Array();
      var descs:Array = new Array();
      var images:Array = new Array();
      var buynow:Array = new Array();
      var saving:Array = new Array();
      var wasprice:Array = new Array();
      var nowprice: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 description into the names Array
              descs.push(linkname[i].attributes.DESC);
              //Push the button link into the links Array
              links.push(linkname[i].attributes.LINK);
              //Push the button link into the links Array
              images.push(linkname[i].attributes.IMG);
              buynow.push(linkname[i].attributes.BUY);
              saving.push(linkname[i].attributes.SAVE);
              wasprice.push(linkname[i].attributes.WAS);
              nowprice.push(linkname[i].attributes.NOW);
              //Attach the button Movie Clip from the libray give it an instance name and place it on the next highest level
              _root.attachMovie("deal1","singledeal"+i,_root.getNextHighestDepth());
              //Set the y position of the buttons
              _root["singledeal"+i]._y = yPosition + -500;
              //Set the x position of the buttons
              _root["singledeal"+i]._x = xPosition + 450;
             
              //Place the button name from names Array into the blackTxt text box
              _root["singledeal"+(i)].blackTxt.Txt.text = (names[i]);
              //Place the button name from names Array into the whiteTxt text box
              _root["singledeal"+(i)].descTxt.Txt.text = (descs[i]);
             
              _root["singledeal"+(i)].holder.loadMovie(images[i]);
              _root["singledeal"+(i)].buynowholder.loadMovie(buynow[i]);
             
              _root["singledeal"+(i)].saveTxt.Txt.text = (saving[i]);
              _root["singledeal"+(i)].wasTxt.Txt.text = (wasprice[i]);
              _root["singledeal"+(i)].nowTxt.Txt.text = (nowprice[i]);
             
             
                      //Assign the btnOver function to the button onRollOver state.
              _root["singledeal"+(i)].onRollOver = btnOver;
              //Assign the btnOut function to the button onRollOut state.
              _root["singledeal"+(i)].onRollOut = btnOut;
              //Assign the btnRelease function to the button onRelease state.
              _root["singledeal"+(i)].onRelease = btnRelease;
             
             
             
                      //Attach the button Movie Clip from the libray give it an instance name and place it on the next highest level
              _root.attachMovie("deal2","doubledeal"+i,_root.getNextHighestDepth());
              //Set the y position of the buttons
              _root["doubledeal"+i]._y = yPosition + -500;
              //Set the x position of the buttons
              _root["doubledeal"+i]._x = xPosition + 450;
             
              //Place the button name from names Array into the blackTxt text box
              _root["doubledeal"+(i)].blackTxt2.Txt.text = (names[i]);
              //Place the button name from names Array into the whiteTxt text box
              _root["doubledeal"+(i)].descTxt2.Txt.text = (descs[i]);
             
              _root["doubledeal"+(i)].holder2.loadMovie(images[i]);
              _root["doubledeal"+(i)].buynowholder2.loadMovie(buynow[i]);
             
              _root["doubledeal"+(i)].saveTxt2.Txt.text = (saving[i]);
              _root["doubledeal"+(i)].wasTxt2.Txt.text = (wasprice[i]);
              _root["doubledeal"+(i)].nowTxt2.Txt.text = (nowprice[i]);
             
             
              //Assign the btnOver function to the button onRollOver state.
              _root["doubledeal"+(i)].onRollOver = btnOver;
              //Assign the btnOut function to the button onRollOut state.
              _root["doubledeal"+(i)].onRollOut = btnOut;
              //Assign the btnRelease function to the button onRelease state.
              _root["doubledeal"+(i)].onRelease = btnRelease;
             
             
             
                      //Attach the button Movie Clip from the libray give it an instance name and place it on the next highest level
              _root.attachMovie("deal3","tripledeal"+i,_root.getNextHighestDepth());
              //Set the y position of the buttons
              _root["tripledeal"+i]._y = yPosition + -500;
              //Set the x position of the buttons
              _root["tripledeal"+i]._x = xPosition + 450;
             
              //Place the button name from names Array into the blackTxt text box
              _root["tripledeal"+(i)].blackTxt2.Txt.text = (names[i]);
              //Place the button name from names Array into the whiteTxt text box
              _root["tripledeal"+(i)].descTxt2.Txt.text = (descs[i]);
             
              _root["tripledeal"+(i)].holder2.loadMovie(images[i]);
              _root["tripledeal"+(i)].buynowholder2.loadMovie(buynow[i]);
             
              _root["tripledeal"+(i)].saveTxt2.Txt.text = (saving[i]);
              _root["tripledeal"+(i)].wasTxt2.Txt.text = (wasprice[i]);
              _root["tripledeal"+(i)].nowTxt2.Txt.text = (nowprice[i]);
             
             
              //Assign the btnOver function to the button onRollOver state.
              _root["tripledeal"+(i)].onRollOver = btnOver;
              //Assign the btnOut function to the button onRollOut state.
              _root["tripledeal"+(i)].onRollOut = btnOut;
              //Assign the btnRelease function to the button onRelease state.
              _root["tripledeal"+(i)].onRelease = btnRelease;   
                     
             
             
             
                      //Attach the button Movie Clip from the libray give it an instance name and place it on the next highest level
              _root.attachMovie("deal0","nodeal"+i,_root.getNextHighestDepth());
              //Set the y position of the buttons
              _root["nodeal"+i]._y = yPosition + -500;
              //Set the x position of the buttons
              _root["nodeal"+i]._x = xPosition + 450;
             
              //Place the button name from names Array into the blackTxt text box
              _root["nodeal"+(i)].blackTxt.Txt.text = (names[i]);
              //Place the button name from names Array into the whiteTxt text box
              _root["nodeal"+(i)].descTxt.Txt.text = (descs[i]);
             
              _root["nodeal"+(i)].holder.loadMovie(images[i]);
             
              _root["nodeal"+(i)].saveTxt.Txt.text = (saving[i]);
              _root["nodeal"+(i)].wasTxt.Txt.text = (wasprice[i]);
              _root["nodeal"+(i)].nowTxt.Txt.text = (nowprice[i]);
             
             
              //Assign the btnOver function to the button onRollOver state.
              _root["nodeal"+(i)].onRollOver = btnOver;
              //Assign the btnOut function to the button onRollOut state.
              _root["nodeal"+(i)].onRollOut = btnOut;       
             
             
             
             
          }
      }
      //Load the XML file
      myXML.load("calendar.xml");

       

      //Button Over function
      function btnOver(){
          //This referse to the current button the mouse is over
          //Go To And Play frame 2 of the current button the mouse is over
          this.gotoAndPlay(2);
      }
      //Button Out function
      function btnOut(){
          //Go To And Play frame 16 of the current button the mouse rolls out from
          this.gotoAndPlay(1);
      }
      //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]);
      }

       

       

       

      Here's the xml for testing:

       

       

       

      <NAVBAR>
          <PROD0 NAME='Deal 8' LINK='http://www.argos.co.uk' DESC='Introducing the new iPod touch. See friends while you talk to them with FaceTime. Shoot, edit, and share stunning HD video. Play games against friends, or unknown foes, with the new Game Center. And do it all on the Retina display-the highest-resolution screen on any mobile device. It makes graphics and text look even more amazing. ' IMG='http://www.argos.co.uk/wcsstore/argos/images/461-7240007IEUC567544M.jpg' BUY='buynow.gif' SAVE='Half Price' WAS='£99.99' NOW='£49.99' />
          <PROD1 NAME='Deal 9' LINK='http://www.argos.co.uk' DESC='Introducing the new iPod touch. See friends while you talk to them with FaceTime. Shoot, edit, and share stunning HD video. Play games against friends, or unknown foes, with the new Game Center. And do it all on the Retina display-the highest-resolution screen on any mobile device. It makes graphics and text look even more amazing. ' IMG='http://www.argos.co.uk/wcsstore/argos/images/25-2719124A70UC502083M.jpg' BUY='buynow.gif' SAVE='Save £20' WAS='£59.99' NOW='£39.99'/>
          <PROD2 NAME='Deal 10' LINK='http://www.argos.co.uk' DESC='Introducing the new iPod touch. See friends while you talk to them with FaceTime. Shoot, edit, and share stunning HD video. Play games against friends, or unknown foes, with the new Game Center. And do it all on the Retina display-the highest-resolution screen on any mobile device. It makes graphics and text look even more amazing. ' IMG='http://www.argos.co.uk/wcsstore/argos/images/2702760SPA66UC295263M.jpg' BUY='buynow.gif' SAVE='Save £20' WAS='£59.99' NOW='£39.99'/>

       

      </NAVBAR>