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.
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;
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();
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;
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"));
}
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"));
}
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"));
}
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.