How to Make SWF Menus

SWF menus are often built into SWF files (multimedia files created with Flash Professional), to access other SWF files. This allows developers to integrate animations in completed SWF files to make a completely new animation. Having a library of SWF files also lets developers create new animations and games quicker. How much quicker, however, depends on how well organized, the number of and the functional quality of the SWF animation library elements. The first step in creating a SWF library is to create a menu system that allows you import your SWF animations into your SWF library.

Things You'll Need

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

Instructions

    • 1

      Start the Flash program. Click "Flash File(ActionScript 3.0)" from the splash window to create a new file for an AS3 Flash animation project.

    • 2

      Select "Actions" from the "Window" menu on the main Flash menu bar to open the ActionScript 3 editor. Position your mouse cursor on the first line of the ActionScript 3 editor. Click your mouse button and type in the code below to create a MovieClip object named movieContainer to be used to view SWF animation files.

      var movieContainer:MovieClip;

    • 3

      Type the code below starting at the next line in the ActionsScript 3 editor to create a ContextMenu object named swfMenu that will be displayed in the Flash animation when the mouse cursor is over the Flash stage and the right mouse button is clicked.

      var swfMenu:ContextMenu = new ContextMenu();

    • 4

      Type the code below starting at the next line in the ActionsScript 3 editor to: prevent the default selections on the Context Menu from being displayed; create a selection option for the ContextMenu called Play_Spin_Ball and the option called Play_Fire_Ball. Then assign them to the ContextMenu that will be displayed on a mouse right-click.

      swfMenu.hideBuiltInItems();

      var firstSwfMovie = new ContextMenuItem("Play_Spin_Ball");

      var secondSwfMovie = new ContextMenuItem("Play_Fire_Ball");

      swfMenu.customItems.push(firstSwfMovie, secondSwfMovie);

      contextMenu = swfMenu;

    • 5

      Type the code below starting at the next line in the ActionsScript 3 editor to assign selection event listeners to the options listed in the ContextMenu that will do the following: check if there is an object in the movieContainer and then remove it; load the Play_Spin_Ball swf file(MasterIllustrationReferenceLibrary.swf). into the movieContainer; play this swf animation on the Flash stage.

      firstSwfMovie.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT, accessMovieLoaders_fn);

      function accessMovieLoaders_fn(e:ContextMenuEvent):void{

      if (movieContainer) {removeChild(movieContainer)};

      var movieLoader:Loader = new Loader();

      movieLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, movieLoaded_fn);

      function movieLoaded_fn(e:Event): void {

      movieContainer = movieLoader.content as MovieClip;

      addChild(movieContainer);

      movieContainer.play();

      }

      movieLoader.load(new URLRequest("MasterIllustrationReferenceLibrary.swf"));

      }

    • 6

      Type the code below starting at the next line in the ActionsScript 3 editor to assign a selection event listener to the Play_Fire_Ball option in the ContextMenu that will do the following: check if there is an object in the movieContainer and then remove the object; load the Play_Spin_Ball swf file(lesson_progress_White_Rabbit_Modified.swf"). into the movieContainer; play this swf animation on the Flash stage.

      secondSwfMovie.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT, accessMovieLoaders2_fn);

      function accessMovieLoaders2_fn(e:ContextMenuEvent):void{

      if (movieContainer) {removeChild(movieContainer)};

      var movieLoader2:Loader = new Loader();

      movieLoader2.contentLoaderInfo.addEventListener(Event.COMPLETE, movieLoaded2_fn);

      function movieLoaded2_fn(e:Event): void {

      movieContainer = movieLoader2.content as MovieClip;

      addChild(movieContainer);

      movieContainer.play();

      }

      movieLoader2.load(new URLRequest("lesson_progress_White_Rabbit_Modified.swf"));

      }

    • 7

      Copy and paste the code into the ActionScript 3 editor to ensure that the program has no syntax errors and runs correctly.

      var movieContainer:MovieClip;

      var swfMenu:ContextMenu = new ContextMenu();

      swfMenu.hideBuiltInItems();

      var firstSwfMovie = new ContextMenuItem("Play_Spin_Ball");

      var secondSwfMovie = new ContextMenuItem("Play_Fire_Ball");

      swfMenu.customItems.push(firstSwfMovie, secondSwfMovie);

      contextMenu = swfMenu;

      firstSwfMovie.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT, accessMovieLoaders_fn);

      function accessMovieLoaders_fn(e:ContextMenuEvent):void{

      if (movieContainer) {removeChild(movieContainer)};

      var movieLoader:Loader = new Loader();

      movieLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, movieLoaded_fn);

      function movieLoaded_fn(e:Event): void {

      movieContainer = movieLoader.content as MovieClip;

      addChild(movieContainer);

      movieContainer.play();

      }

      movieLoader.load(new URLRequest("MasterIllustrationReferenceLibrary.swf"));

      }

      secondSwfMovie.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT, accessMovieLoaders2_fn);

      function accessMovieLoaders2_fn(e:ContextMenuEvent):void{

      if (movieContainer) {removeChild(movieContainer)};

      var movieLoader2:Loader = new Loader();

      movieLoader2.contentLoaderInfo.addEventListener(Event.COMPLETE, movieLoaded2_fn);

      function movieLoaded2_fn(e:Event): void {

      movieContainer = movieLoader2.content as MovieClip;

      addChild(movieContainer);

      movieContainer.play();

      }

      movieLoader2.load(new URLRequest("lesson_progress_White_Rabbit_Modified.swf"));

      }

    • 8

      Click "Test Movie" in the "Control" menu to play the Flash swf library movie. Right-click your mouse and click the "Play_Spin_Ball" option and observe that this movie plays. Right click the "Play_Fire_Ball" option and observe that the "Play_Spin_Ball" movie has been replaced with the "Play_Fire_Ball" movie.

Learnify Hub © www.0685.com All Rights Reserved