4 Replies Latest reply on Aug 8, 2007 8:52 AM by cicnats

    Function on frame 1, to execute function on frame 3 ?

    maith Level 1
      Hi,
      I have a button on frame 1, which executes a function, which goes to frame 3. I want it to execute a function, called FILL () on frame 3, which enters text into a dynamic text field. The function FILL () works when executed on frame 3.
      The code on Frame 1 is:
      myButt.onRelease = function () {
      gotoAndStop(3);
      FILL () ;
      }
      It will goto frame 3 but how can I get it to execute the function FILL () on frame 3 ?

      Thanks,
      Paul
        • 1. Re: Function on frame 1, to execute function on frame 3 ?
          Level 7
          Put the function on frame 1 - and be sure not to keyframe your script layer.
          It will then be available on frame 3, or any frame for that matter.

          --
          Dave -
          Head Developer
          http://www.blurredistinction.com
          Adobe Community Expert
          http://www.adobe.com/communities/experts/


          • 2. Re: Function on frame 1, to execute function on frame 3 ?
            clbeech Level 3
            if for some reason you still need the function to run on 3, another method would be to call the function like so:

            function FILL() {
            ...
            }

            FILL();

            then on reaching frame 3, the function will execute, once.
            • 3. Re: Function on frame 1, to execute function on frame 3 ?
              maith Level 1
              Thanks , I didn't realise you could do that. Even though it wasn't what I was looking for. It turns out I needed to pass a variable to the function on frame 1 and then use that variable, with an if statement on frame 3 to call a function on frame 3.
              So I figured it out and its working now.

              Thanks again,
              Paul
              • 4. Function on frame 1, to execute function on frame 3 ?
                cicnats Level 1
                I believe it's best to define all the functions at the start, instead on different frames. So you don't have to consider if a function is defined or not. Once you define a function inside a movie clip or stage it remains defined until you redefine or delete it, or remove the movie clip that contains it. Also there's nothing wrong if an object referenced inside the function (like your text field) doesn't exist on the frame that the function is defined as long as it exists when the function is called;

                Also it's a good idea to have functions in an external .as file instead of inside keyframes..

                now that i've read your question again I think that's probably not what you were asking..

                gotoAndStop/Play changes the current frame before displaying the next frame, that means after all the code on the frame when the action was called finishes. You can write (I think)

                gotoAndStop(3);
                gotoAndStop(4);

                and it will jump to frame 4 on the next frame, and not even touch frame 3 (I think)

                so you just have to put a call to your function on frame 3 and it will execute every time you jump to frame 3, if that's what you want.. if not, you could add this to your code

                gotoAndStop(3);
                onEnterFrame = function() {
                FILL();
                delete onEnterFrame;
                }

                if you are not already using the onEnterFrame event.. if you are.. you can use the same idea, just modify it a bit..