How to Call a Function at the End of a Movie Clip

In the Flash animation environment, you can create movie clips without ever having to program a line of code. However, there are limitations. If, for example, you want your movie clip to transfer your visitors to your main webpage when the movie ends, you will have to be able to code a Flash function. Programming code in Flash is done with ActionScript 3, the Flash programming language. Although coding a simple function takes little time, you must follow the correct syntax for writing the code and place the code in the right frame on the timeline.

Things You'll Need

  • Adobe Flash Professional CS3, CS4 or CS5 version
Show More

Instructions

    • 1

      Open the Flash file that contains the movie clip that you want to add an end function to.

    • 2

      Click the "Timeline" option from the "Window" menu. Locate the last frame on the timeline where the movie clip ends. Click inside the last frame icon to select the last frame, Click the "Actions" option from the "Window" menu to open the ActionScript 3 editor.

    • 3

      Position your mouse cursor on the first line of the ActionScript 3 editor. Click the mouse button, and type the following code, which will set a timer that will time out in three seconds (3,000 milliseconds).

      var transferTimer: Timer = new Timer(3000, 1);

    • 4

      Type the code starting at the next line of the ActionScript 3 editor to activate the timer. Attach the "start" method to the "transferTimer" timer object.

      transferTimer.start();

    • 5

      Type the code starting at the next line of the ActionScript 3 editor to add an event listener to the transferTimer such that when the timer has elapsed (three seconds have passed) the instructions in a function named "changeURL_fn" will be executed.

      transferTimer.addEventListener(TimerEvent.Timer, changeURL_fn);

    • 6

      Type the code starting at the next line of the ActionScript 3 editor to create the function named "changeURL_fn."

      function changeURL_fn(event: TimerEvent): void

    • 7

      Type the code (instructions) that the changetoURL function will execute within curly brackets beginning on the next line in the ActionScript 3 editor. Use the "navigateToURL" method with the URL of the web page you want to navigate to as the argument for the navigateToURL method.

      {

      var URL:String = "http://www.adobe.com";

      navigateToURL(URL);

      };

Learnify Hub © www.0685.com All Rights Reserved