4 Replies Latest reply on Sep 11, 2010 8:31 AM by kglad

    adding submenus to an xml driven main menu

    daymonic Level 1

      Hi there folks,

       

      I have been following and bastardising a computer arts tutorial for a dynamic flash site, its a really good tutorial and I'd like to keep going with that format/style, but I'm pretty new to the whole scripting thing and am finding it a bit of a headache, so was wondering if any kind souls would help me work out how to add submenus to the code below. the main menu button is a movie file(btn_projects_main) consisting of a button (button) and a text box(txt) and is 3 frames long to allow for the different states:
      What I'm looking for is a set of sub menus which load horizontally below the main menu buttons, here is the code which has been altered slightly (thanks to Ned Murphy for his help and patience with that) any help would be hugely appreciated :

       

      // Setup some initial variables

       

      // Hide the button that will display a web link
      _root.theUrl._visible = 0;

       

      // Hide the image icons in the project loader
      // The image icons are simply there to make it easier for you to
      // select the movieClip from the main timeline.
      _root.img_project.photo_icon._visible = 0;
      _root.img_project.img_holder.photo_icon2._visible = 0;

       

      // name of the folder for all thumbs and swf files
      _root.imageFolder = "project_files/";

       

      // Create arrays ready for the xml data
      namesArray = new Array();
      linksArray = new Array();
      descriptionsArray = new Array();
      filesArray = new Array();

       

      // Load XML doc
      objXML = new XML();
      objXML.onLoad = loadXML;
      objXML.ignoreWhite = true;
      // The name of your XML file
      objXML.load("ss_flash_testing.xml");

       

      /////////////////////////////////////////////////////////////////////////////////////////

       

      // onLoad XML function
      function loadXML(success) {
      if (success) {
      // If the XML loads successfully, count how many projects there are in the file.
      _root.projectCount = this.firstChild.childNodes.length; // PROJECT node in XML file
      // Then run a function that builds arrays out of the XML data.
      SS_Arrays();
      } else {
      // If the xml data did not load, show message on stage by populating the description field.
      _root.description = "Error: Could not load XML";
      }
      }

       

      /////////////////////////////////////////////////////////////////////////////////////////

       

      function SS_Arrays() {
      for (var count = 0; count < _root.projectCount; count++) {
      var nodeObj = objXML.firstChild.childNodes[count];
      namesArray[count] = nodeObj.attributes.name;
      descriptionsArray[count] = nodeObj.attributes.description;
      linksArray[count] = nodeObj.attributes.link;
      filesArray[count] = nodeObj.attributes.file;
      }
      // run the function to create the thumbnail and list view buttons
      SS_createButtons();
      }

       

      /////////////////////////////////////////////////////////////////////////////////////////

       


      var spaceBetween = 60; // space between buttons

       

      function SS_createButtons() {
      btn_projects_main._visible = 0;
      btn_xPos = _root.btn_projects_main._x;
      btn_yPos = _root.btn_projects_main._y;

       

      for (count = 0; count < namesArray.length; count++) {
      duplicateMovieClip(btn_projects_main, "btn_projects" + count, count);

       

      this["btn_projects" + count]._x = btn_xPos;
      this["btn_projects" + count]._y = btn_yPos;

       

      this["btn_projects" + count].txt.autoSize = "left";
      this["btn_projects" + count].txt.text = namesArray[count];

       

      //set the button width
      this["btn_projects" + count].btn._width = this["btn_projects" + count].txt._width;

       

      // determine the new x placement value based on the current button's width
      btn_xPos = btn_xPos + this["btn_projects" + count]._width + spaceBetween;
      }

       

      // anything from here down I have no idea if it's needed, so I left it

       

      SS_load_project(0);

       

      tellTarget(_root.btn_projects0){
      gotoAndPlay(3);
      }

       

      _root.curButton = "0";
      }

       

      SS_createButtons(); // to kick off the function

       

      /////////////////////////////////////////////////////////////////////////////////////////

       

      function SS_load_project(arrayNumber){

       

      /////////////////////////////////////////////////////////////////////////////////////////

       

      // Progress bar stuff: This creates a new movie clip on the stage
      // and shows the progress of the image or file being loaded

       

      _root.createEmptyMovieClip("progressBar_mc", 1000);
      progressBar_mc.createEmptyMovieClip("bar_mc", 1001);
      // Using the flash drawing method, draw a box 550px wide by 2px deep
      // with a fill of red (FF0000)
      with (progressBar_mc.bar_mc) {
      beginFill(0xFF0000, 100);
      moveTo(0, 0);
      lineTo(660, 0);
      lineTo(660, 2);
      lineTo(0, 2);
      lineTo(0, 0);
      endFill();
      _xscale = 0;
      }

       

      // set the X & Y positions of the progress bar manually
      //progressBar_mc._x = 160;
      //progressBar_mc._y = 218;

       

      // Or set them to be the same X & Y as the project file/image.
      progressBar_mc._x = img_project._x;
      progressBar_mc._y = img_project._y;

       

      // set the initial width of the bar to zero
      var mclListener:Object = new Object();
      mclListener.onLoadStart = function(target_mc:MovieClip) {
      progressBar_mc.bar_mc._xscale = 0;
      }

       

      // increase the width (xscale) of the bar as the file loads
      mclListener.onLoadProgress = function(target_mc:MovieClip, bytesLoaded:Number, bytesTotal:Number) {
      progressBar_mc.bar_mc._xscale = Math.round(bytesLoaded/bytesTotal*100);
      // Make sure the clip being loaded doesn't play until it is fully loaded.
      // If you want content to stream as it loads remove the following 3 lines
      tellTarget(_root.img_project.img_holder){
      stop();
      }     
      }

       

      // once the file has loaded, remove the progress bar from the stage
      mclListener.onLoadComplete = function(target_mc:MovieClip) {
      progressBar_mc.removeMovieClip();
      // Plays the loaded clip once it's fully loaded.
      // If you want content to stream as it loads remove the following 3 lines
      tellTarget(_root.img_project.img_holder){
      play();
      }     
      }

       

      /////////////////////////////////////////////////////////////////////////////////////////

       

      // Load the project file onto the stage by loading it into a movieClip (which in this case
      // is inside another one img_project > img_holder.

       

      var image_mcl:MovieClipLoader = new MovieClipLoader();
      image_mcl.addListener(mclListener);

       

      // load the clip onto the stage into a movieClip
      image_mcl.loadClip(_root.imageFolder + _root.filesArray[arrayNumber], img_project.img_holder);

       

      // Populate the dynamic text fields on the main stage with the project title & description
      _root.prj_name = _root.namesArray[arrayNumber];     
      _root.prj_description = _root.descriptionsArray[arrayNumber];

       

      // if the URL is present for this project, populate & show the link
      if(_root.linksArray[arrayNumber] != "") {
      _root.btn_link.webAddress = _root.linksArray[arrayNumber];
      _root.btn_link._visible = 1;
      } else {
      _root.btn_link._visible = 0;
      }

       

      // Reset the last button
      tellTarget("_root.btn_projects" + _root.curButton){
      gotoAndPlay(1);
      }

       

      // Replace the current button variable with this projects id/number     
      _root.curButton = arrayNumber;
      }

       


      stop();