6 Replies Latest reply on Dec 9, 2008 7:13 PM by LostFlashGirl

    how do I create a chain reaction?

    shintashi Level 1
      suppose I've got something like this

      -----------
      var myListener:Object = new Object();
      myListener.onKeyDown = function() {
      if (Key.getCode() == Key.SPACE) {
      icon1_mc.gotoAndStop("frame2");
      icon1_mc.gotoAndStop("frame3");
      icon1_mc.gotoAndStop("frame1");
      }
      };
      Key.addListener(myListener);
      -------------

      clearly this wont work because the frames are interfering with each other. What method does a person use to trigger a small sequence of events, such as playing frame 1, then 2, then 3 where it stops, without relying on a preloaded frame sequence?
        • 1. Re: how do I create a chain reaction?
          LostFlashGirl
          You were very close. Try this:

          //---------------
          var myListener:Object = new Object();
          myListener.onKeyDown = function() {
          if (Key.getCode() == Key.SPACE) {
          icon1_mc.nextFrame();
          }
          };
          Key.addListener(myListener);
          stop();
          //--------------------

          I have taken the three named frames out and placed in a single command referencing your instance clip... ".nextFrame()" - sends the clip to the next frame in its sequence and stops it. Of course, when you get to the last frame in your sequence you need to go back to the start. Repost here if you have difficulties with it.

          - LFG
          • 2. Re: how do I create a chain reaction?
            shintashi Level 1
            while not exactly what I needed, I can definitely use .nextFrame for programming, since I've never seen it before. I normally learn flash code haphazardly.

            Thank you :)
            • 3. Re: how do I create a chain reaction?
              kglad Adobe Community Professional & MVP
              are you trying to play a (non-sequential) series of frames for a particular movieclip?
              • 4. Re: how do I create a chain reaction?
                shintashi Level 1
                its my first attempt at arrays that actually do something useful. I created four movie clips with button like function, (mouse over, on press, rollout) with specific functions, and I wanted the option to select them using keyboard instead of mouse, using shift. I got all that working and made "spacebar" the main button: click the spacebar and whatever button is highlighted (determined by an array linked to the shift key) acts as if it has been clicked.

                I wanted the spacebar press and release to resemble a mouse press and release, but I think what I really need to do is attach an array effect that tells the buttons when highlighted to act as if mouse is over, since it's the mouse over (not the on press) that it's really zipping through too quickly to see. I would prefer if the spacebar is pressed down, and held, it goes to frame 2 (mouse over) and stays, but if released it goes to frame 3, activates the effect, then returns to frame 1.
                • 5. Re: how do I create a chain reaction?
                  kglad Adobe Community Professional & MVP
                  what effect is activated on frame 3?
                  • 6. Re: how do I create a chain reaction?
                    LostFlashGirl Level 1
                    by creating multiple listners the effect may be more successful?

                    //------------------------------------
                    icon1_mc.stop();
                    var myListener:Object = new Object();
                    myListener.onKeyDown = function() {
                    if (Key.getCode() == Key.SPACE) {
                    icon1_mc.gotoAndStop(2);
                    }
                    };
                    Key.addListener(myListener);

                    var myListener2:Object = new Object();
                    myListener2.onKeyUp = function() {
                    if (Key.getCode() == Key.SPACE) {
                    icon1_mc.gotoAndStop(3);
                    // .... //insert other commands here for button release
                    // once other commands are processed, return button to first frame
                    //> icon1_mc.gotoAndStop(1);
                    }
                    };
                    Key.addListener(myListener2);

                    stop();
                    //------------------------------------

                    i should point out that if the symbol icon1_mc is a button the code above will not effect it, but if you convert it to a Movie Clip it does. Perhaps using it as a Movie Clip and manually coding the mouseOver reactins as well may create the desired effect? i can see what you are trying to do, although the Shift key involvement i have not implemented in my version. im sure kglad will know more but i find varying attempts, even if failures, simply narrows the sussessful possibilities. Edison didnt fail a heap of times, he just found a lot of ways NOT to make a lightbulb. hope some of this was of help.

                    - LFG