34 Replies Latest reply on Jun 15, 2007 12:23 PM by kglad

    listen for frame

    Damon Edwards Level 3
      ive added about 10 different frame numbers that i want to listen for in an array, ive added a listener to that array.. now, i want to add an if statement saying that if the current frame number is in that array, do something. however, its not working like i'd hoped. i need to be steered in the right direction.
        • 1. Re: listen for frame
          whodeee
          what I would do is try using a for loop to go through the indexes of your num_array
          • 2. Re: listen for frame
            Damon Edwards Level 3
            i tried this... didnt work..
            • 3. Re: listen for frame
              kglad Adobe Community Professional & MVP
              there are a lot of problems with that. but to start, there's no addListener method for arrays.
              • 4. Re: listen for frame
                Level 7
                Listeners can only be attached to classes that can broadcast events. An
                array isn't one of those. In AS2, you can attach a listener to: Key,
                Mouse, MovieClipLoader, Selection, Stage and Textfield. Further, you
                need to connect the listener to an event.

                You don't really need, or want, to use a listener for the work that you
                want to do here. You can use a simple onEnterFrame event to trigger the
                frame number test that you have in mind.

                Something like this may do what you need:

                var num_array:Array = new Array(96, 207, 318, 429, 540, 651, 762, 873);

                this.onEnterFrame = function() {
                if( _currentframe == num_array){
                gotoAndPlay(96 + 111*getIndex(arr, addr));
                };
                }

                Using the keyword "this" will attach the onEnterFrame function to the
                current timeline. You could also specify any movieClip instance if you
                like, as long as that clip will be available anywhere that you need to
                use that method.
                • 5. Re: listen for frame
                  Damon Edwards Level 3
                  i was wondering why it didnt list that in the code hint... can you think of another way to go about what im trying to do? this is all on frame one, and when the timeline hits one of those frames i need it to jump to the corresponding frame based on
                  96 + 111*getIndex(arr, addr) which works just fine. if i trace that out, it gives me the right number from the arr array. i just cant get it to know when its on one of the frames and then do something
                  • 6. Re: listen for frame
                    kglad Adobe Community Professional & MVP
                    you need to create a loop (like onEnterFrame or setInterval) that repeatedly checks your timeline's _currentframe and checks that against each of your array elements (use a for-loop).

                    or, on each of those frames place a function call to a function that does what you want.
                    • 7. Re: listen for frame
                      Pop_Clingwrap Level 1
                      how about:
                      var arraycount:Number = 0;

                      _root.onEnterFrame = function()
                      {
                      var fr:Number = _root._currentframe;
                      if(fr == yourArrayOfFrames[arracount])
                      {
                      arraycount++;
                      yourTargetClip.gotoAndPlay(fr);
                      }
                      }

                      I have assumed some stuff and referenced some names that may be different in yours but it might work. Might give you some ideas anyway
                      • 8. listen for frame
                        Damon Edwards Level 3
                        kglad,
                        i've been attempting to do what you mentioned 2nd, but i dont know how to grab the getIndex(arr, addr) values from the onChange function on frame 1.
                        • 9. Re: listen for frame
                          kglad Adobe Community Professional & MVP
                          what's getIndex and what's arr and what's addr and what's onChange checking?
                          • 10. Re: listen for frame
                            Damon Edwards Level 3
                            when you click a button, it sets a value and the onChange function grabs that value and assigns that value to addr , all those values are stored in a common array 'arr', when i just call
                            gotoAndPlay(96 + 111*getIndex(arr, addr)); // so getIndex(arr, addr) is really a number based on what button is pressed.

                            if i clicked the first button (in arr its index is 0), it will go to frame 96, second button (arr index of 1), it will go to frame 207. instead of doing that, id rather it played when i clicked a button, then when it hits one of those frames it will jump to the correct frame based on getIndex(arr, addr).. is that coherent?
                            • 11. Re: listen for frame
                              kglad Adobe Community Professional & MVP
                              when you click a particular button, you're do something (what?) and then afterwards you gotoAndPlay frame 96+111*whatIndex, where whatIndex is determined by which button you pressed or by the number of buttons you pressed before that button or by something else?
                              • 12. Re: listen for frame
                                Damon Edwards Level 3
                                clicking a button = Blah.setValue('/whatever/'); or could be Blah.setValue('/whatever3/'); depending on button

                                on actions layer =
                                function getIndex(arr, obj) {
                                for (var i = 0; i<arr.length; i++) {
                                if (arr == obj) {
                                return i;
                                }
                                }
                                }
                                Blah.onChange = function() {
                                var arr = new Array('/whatever/', '/whatever2/', '/whatever3/', '/whatever4/', '/whatever5/', '/whatever6/', '/whatever7/', '/whatever8/');
                                var addr = Blah.getValue();
                                play(); //then when it gets to a particular frame, it should jump to the frame based on 96 + 111*getIndex(arr, addr)
                                };
                                • 13. Re: listen for frame
                                  kglad Adobe Community Professional & MVP
                                  use the attach code option to display code.

                                  explain, for example, what should happen if i press buttons 1,3 and 2 in the first 2 seconds of viewing your swf.
                                  • 14. listen for frame
                                    Damon Edwards Level 3
                                    well right now, since it's only set to play(); nothing, you would end up where my first stop(); action is.. if i replace play with gotoAndPlay(96 + 111*getIndex(arr, addr));
                                    you'd end up on the frame of the last button you pressed, so if it was button 2 (index of 1), you'd end up on 96+111*1 == frame 207
                                    • 15. Re: listen for frame
                                      kglad Adobe Community Professional & MVP
                                      well, i should have asked, "what is it that you want to happen"?

                                      if you just want to go to the button index times 111 plus 96, use:

                                      • 16. listen for frame
                                        Damon Edwards Level 3
                                        i do want that, but first i want the timeline to play, then do that once it hits a certain frame..

                                        basically saying, play, then when you get to 'x' frame goto and play this frame based on the button you pressed.
                                        • 17. Re: listen for frame
                                          kglad Adobe Community Professional & MVP
                                          the timeline plays from where to where before going to the designated frame? and does it play that sequence repeatedly with each button press?
                                          • 18. Re: listen for frame
                                            Damon Edwards Level 3
                                            there are stop(); acions on frame 111 222 333 444 555 666 and so on, where all my content is, in between is a masking effect, so on frame 96 207 and so on, is where the mask starts to peal away... so it should play through the masking, then just where it starts to peal away, is where it jumps to the new frame peeling away revealing new content
                                            • 19. Re: listen for frame
                                              kglad Adobe Community Professional & MVP
                                              so, if someone presses buttons 1,3 and 2 in rapid succession you want to play frames 96 to 111, 318 to 333 and 207 to 222 without stopping until frame 222?
                                              • 20. Re: listen for frame
                                                Damon Edwards Level 3
                                                no.. when they press a button, all it should do is play (as it is storing the value for the button pressed), then if it hits frame 96 207 318 etc, is when it should grab the value and take them to the correct frame. so if they hit 1,3 then 2 in rapid succession, it would play, then hit frame 96 since it would still be at the beginning of the timeline, and it would grab the index value for button two from getIndex(arr, addr), which would be '1', then take them to 96+111*'1'. if they pressed 2,6 then 3 extremely fast, it would hit frame 96, then grab the index value for button 3 from getIndex(arr, addr), which would take them to 96+111*'2'... make sense?
                                                • 21. Re: listen for frame
                                                  kglad Adobe Community Professional & MVP
                                                  what's playing before frame 96?
                                                  • 22. Re: listen for frame
                                                    Damon Edwards Level 3
                                                    the mask that leads up to the first content
                                                    • 23. Re: listen for frame
                                                      kglad Adobe Community Professional & MVP
                                                      so frame 1 to 96 is an intro that would play before everything else?
                                                      • 24. listen for frame
                                                        Damon Edwards Level 3
                                                        yes, if you want to see what im saying visit

                                                        http://www.imediapro.com/damonTesting/
                                                        • 25. Re: listen for frame
                                                          kglad Adobe Community Professional & MVP
                                                          then all you need to do is place the following on frame 96 and have each button direct the timeline to play 1 to 96 AND set the value of a variable (say, buttonNumber) to match the button number:

                                                          • 26. Re: listen for frame
                                                            Damon Edwards Level 3
                                                            that wont work, because, i want the the timeline to just play after a button is clicked, so you see the content that was just there getting masked, then it jumps to the correct frame when the mask is starting to tear away... all i really need, is to be able to access (arr, addr); from frame one, on frame 96 207 etc... they are inside a function and i dont know how to get to them so when you hit the frame, it recognizes (arr, addr);
                                                            • 27. Re: listen for frame
                                                              kglad Adobe Community Professional & MVP
                                                              if you press a button, frames 1 to 96 play and then you jump to the correct frame (which varies depending upon which button was pressed).

                                                              or do frames 1 to 96 only play when you first start your swf and never again?
                                                              • 28. Re: listen for frame
                                                                Damon Edwards Level 3
                                                                yes, they only play once, that transition is breaking up all the content.
                                                                • 29. Re: listen for frame
                                                                  kglad Adobe Community Professional & MVP
                                                                  if i press buttons 1,3 and 2 with a 1 minute interval between each button press. what frames play?
                                                                  • 30. Re: listen for frame
                                                                    Damon Edwards Level 3
                                                                    assuming you let it stop at the first point (frame 111) 112-222 stop. 223-333 stop. 334-444. as of right now because it's only set to play, so no matter what button you press its just going to play... if it did want i want it would be like this, same situation
                                                                    waiting till it stopped at first point. 112-207jumpto96-111 stop (after hitting button 1). 112-207jumpto318-333 stop (after hitting button 3). 334-429jumpto207-222 stop (affter hitting button 2)
                                                                    • 31. Re: listen for frame
                                                                      Damon Edwards Level 3
                                                                      if you go there right now
                                                                      http://www.imediapro.com/damonTesting/index.html

                                                                      and press a button you'll see how it takes you to the end of the transition, well i want it to just play first then go to the right frame when it hits one of those certain frames. here is what i have now to make it do what its doing.. if theres a way to just have it play then when it gets to a frame do what its doing.. which is why i wanted to listen for a frame, which isnt possible i guess.
                                                                      • 32. Re: listen for frame
                                                                        kglad Adobe Community Professional & MVP
                                                                        if you press

                                                                        button 1, it should play: 112-207, then 96-111
                                                                        button 3, it should play: 112-207, then 318-333
                                                                        button 2, it should play: 334-429, then 207-222

                                                                        is there a pattern there?

                                                                        is this only to display an "outro" (if a previous button has been pressed)?
                                                                        • 33. Re: listen for frame
                                                                          Damon Edwards Level 3
                                                                          i guess im just not explaining it well enough, i know its a lot easier if its right in front of you, but thats not an option with this... im really thankful that you stuck with me this long, i think im just going to go another route, and just bite my tongue and let the mask play how it does, even though its not very appealing to me.. Thanks again though for your effort.
                                                                          • 34. Re: listen for frame
                                                                            kglad Adobe Community Professional & MVP
                                                                            you're welcome.