5 Replies Latest reply on Oct 16, 2008 10:41 AM by clbeech

    setTimeout in MC?

    shintashi Level 1
      Hi, I'm having a lot of difficulty trying to get a delay effect.
      The objective: do not load another MC until the first MC animation has finished (using 30 fps; animation is 20 frames, so 2/3rds of a second, or 2/3000). So something like this


      except I don't know how to stick it into the code and it's clear I'm missing something.

        • 1. Re: setTimeout in MC?
          clbeech Level 3
          well - instead of using a 'timed' system why not have the 'bullet' change a variable when it gets the 'end' of it's animation - setting a boolean to true so that then you condition statement will execute. so then you would say in the above loop -

          if(cleared && Key.isDown(Key.enter)) { cleared=false; ... }
          • 2. Re: setTimeout in MC?
            shintashi Level 1
            I have almost no experience with booleans, but I know if I put this


            if (cleared && Key.isDown(Key.ENTER)){



            in the MC, something is missing, and it doesn't work.

            How do I get the 20th frame of a loaded/attached MC to ring true, aka cleared=true; ?
            • 3. Re: setTimeout in MC?
              clbeech Level 3
              ok - first of all, you should really try to steer away from 'attaching' scripts to objects and place all of your code on the timeline instead, usually in a separate layer commonly called 'actions'. in this case then you would create a method that runs the onEnterFrame event and a 'global' variable - the boolean - which is declared outside the method. then when your bullet finishes it's animation, on the final frame you would call to change the value of the variable that would be on the 'root' timeline - so agian in a layer called actions in the bullet MC on the last frame - insert a keyframe and then call to: _root.cleared=true; to 'reset' the var.

              but this will only work if you have the code and the variable on the main timeline. don't forget that if you do move your codes to the timeline (which you really should) you need to delete all other code that you currently have 'attached' to the objects - so you codes would end up looking like this:
              • 4. Re: setTimeout in MC?
                shintashi Level 1
                When I tried the above solution, I had to add another _root.cleared = true; to the final target (this is a multi-stage collision detection: button pushed, round loads and begins traveling. If round impacts target, round explodes, causes damage and removes self from stage.) otherwise it just fired like before and stopped altogether on impact. Once I set that effect in place, it exploded and took damage like normal, but the firing delay still hasn't worked.

                Is there no way to do the global setTimeout? or is that Taboo for some reason?
                • 5. Re: setTimeout in MC?
                  clbeech Level 3
                  well using a timeout wont solve your problem. the event will still continue to execute regardless of a 'timeout' it's not the way to handle the situation - you will need to use a boolean variable if you are using a loop to execute the attachment method. there are several other ways to go about this - setTimeout is not the answer - it just wont work. you need to use a conditional statement to determine whether or not the bullet should be able to fire - regardless of the collision. yes - if at any time your collision detection system is activated you then need to change the variable so that the next shot can be fired.

                  did you place the code on the timeline then?
                  did you remove all other 'object attached' codes?