1 Reply Latest reply on Oct 12, 2012 6:15 AM by Ned Murphy

    Arrays :(

    DMB89

      Hi everyone.

       

      I have created 3 buttons on my stage called retail_btn, residential_btn and heritage_btn.

       

      I have then created a list of arrays and added some simple onRollOver, onRollOut and onPress fuctions like so...

       

      var btn:Array = [retail_btn, residential_btn, heritage_btn];

      for (var i = 0; i < 3; i++)

      {

          btn[i].onRollOver = function()

          {

              this.gotoAndStop(2);

          };

          btn[i].onRollOut = function()

          {

              this.gotoAndStop(1);

          };

          btn[i].onPress = function()

          {

              playPopup_mc();

              this.gotoAndStop(1); // returns MC state to normal.

          };

      }

       

      I have then got a function called playPopup_mc that plays a MC called popup_mc also already on the stage like so...

       

      function playPopup_mc()

      {

          popup_mc.onEnterFrame = function()

          {

              if (this._currentframe != 20)

              {

                  this.nextFrame();

                  this.invisible_btn.useHandCursor = false;           

              }

              else

              {

                  this.stop();

                  delete this["onEnterFrame"];

              }

          };   

      }

       

      What I then need to do (this is the bit i am struggling with) is create another list of arrays to pull a specific MC from the library onto the stage depending on the button i originally clicked.

       

      For example something along these lines:

       

      function playPopup_mc()

      {

          popup_mc.onEnterFrame = function()

          {

              if (this._currentframe != 20)

              {

                  this.nextFrame();

                  this.invisible_btn.useHandCursor = false;

                 var cs:Array = ["retail_btn_cs", "residential_btn_cs", "heritage_btn_cs"];

                  for (var i = 0; i < 2; i++)

                  {

                      popup_mc.attachMovie(btn[1],btn[1],0);

                  }

              }

              else

              {

                  this.stop();

                  delete this["onEnterFrame"];

              }

          };

      }

       

      This doesnt work as it cannot define / determine the value cs[i]. However I dont know what I am missing out. Any help would be much appriciated, thank you.

        • 1. Re: Arrays :(
          Ned Murphy Adobe Community Professional & MVP

          Think in terms of passing the button used to the function, or to simplify it even more by assigning a property to the buttons that equals the linkage name of the popup you want it to show and passing that to the function.

           

          // outside

          var btn:Array = [retail_btn, residential_btn, heritage_btn];

          retail_btn.popupLinkage = "retail_btn_cs";

          residential_btn.popupLinkage = "residential_btn_cs";

          heritage_btn.popupLinkage = "heritage_btn_cs";

           

          //... inside

              btn[i].onPress = function()

              {

                  playPopup_mc(this.popupLinkage);

                  this.gotoAndStop(1); // returns MC state to normal.

              };

          1 person found this helpful