3 Replies Latest reply on Dec 13, 2008 1:27 PM by Ned Murphy

    Array to control MCs on the root timeline

    jl2000 Level 1
      HI - - - a continuing saga

      I have a main timeline thats about 900 frames long. During the course of this 900 frames I bring in short MCs (subA, subB, subC, etc) on their own layer which play their duration - (a 90 frame sub MC gets 90 frames on the main timeline).

      Using a mc I made into a play/pause btn, I can pause and resume play of the main timeline by targeting “_root”.
      I can also use the same button to pause/play the sub_mcs IF I list each one at the pause and play commands. I thought an array would help me avoid that code repetition but it doesn't work.

      Can someone look at my code and let me know what's missing and/or what I did wrong?

      TIA

      JL
        • 1. Re: Array to control MCs on the root timeline
          Level 7
          Hi --

          Try this:

          obj = allSubMCs[0]
          obj.play();

          etc..

          You have to define the index of the array. If you want the pause/play button
          to work for all MCs in the array then just loop through the array.

          Rich


          "jlucchesi" <webforumsuser@macromedia.com> wrote in message
          news:ghun7u$pjn$1@forums.macromedia.com...
          > HI - - - a continuing saga
          >
          > I have a main timeline thats about 900 frames long. During the course of
          > this
          > 900 frames I bring in short MCs (subA, subB, subC, etc) on their own layer
          > which play their duration - (a 90 frame sub MC gets 90 frames on the main
          > timeline).
          >
          > Using a mc I made into a play/pause btn, I can pause and resume play of
          > the
          > main timeline by targeting ?_root?.
          > I can also use the same button to pause/play the sub_mcs IF I list each
          > one at
          > the pause and play commands. I thought an array would help me avoid that
          > code
          > repetition but it doesn't work.
          >
          > Can someone look at my code and let me know what's missing and/or what I
          > did
          > wrong?
          >
          > TIA
          >
          > JL
          >
          > var allSubMCs:Array = new Array("sub1_mc", "sub2_mc", "sub3_mc");
          >
          >
          > playPause_btn.onRollOver = function() {
          >
          > if(this._currentframe == 1) {
          > this.gotoAndStop("pauseOver");
          > }
          >
          > else {
          > this.gotoAndStop("playOver");
          > }
          >
          > }
          >
          >
          > playPause_btn.onRollOut = function() {
          >
          > if(this._currentframe == 10) {
          > this.gotoAndStop("pause");
          > }
          >
          > else {
          > this.gotoAndStop("play");
          > }
          >
          > }
          >
          >
          > playPause_btn.onRelease = function() {
          >
          > if(this._currentframe == 10) {
          > this.gotoAndStop("playOver");
          > _root.sub1_mc.stop(); // naming each sub mc does
          > //_root.allSubMCs.stop(); // the array doesn't work
          > _root.stop();
          > }
          >
          > else {
          > this.gotoAndStop("pauseOver");
          > //_root.allSubMCs.play(); // the array doesn't work
          > _root.sub1_mc.play(); // naming each sub mc does
          > _root.play();
          > }
          >
          > }
          > //------END PlayPause TOGGLE--------
          >


          • 2. Re: Array to control MCs on the root timeline
            jl2000 Level 1
            Rich -
            Thanks for the response. I should have opened my question with "Actionscript challenged".
            Where/how do I use your code? Is this AS2? (That's what I'm publishing as).

            I tried it before and after:
            var allSubMCs:Array = new Array("sub1_mc", "sub2_mc", "sub3_mc");
            with no result.

            I need a little more explanation please.

            JL
            • 3. Array to control MCs on the root timeline
              Ned Murphy Adobe Community Professional & MVP
              Use...

              _root[allSubMCs[0]].stop();

              There are two problems with what you did...

              1) you need to specify a specific index of the array

              allSubMCs[0] gives you the string... "sub1_mc"

              2) the array only contains strings, not movieclip objects, so you need to have those strings evaluated as object instances. The brackets surrounding the array element value will do that.

              _root[allSubMCs[0]] targets the instance