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 AS3 editor. Click your cursor on the first line of the editor and type in the code below to load the animation that you previously created and saved as"MasterIllustrationReferenceLibrary.swf" into this new Flash animation project.
var movieContainer:MovieClip;
var movieLoader:Loader = new Loader();
movieLoader.load(new URLRequest("MasterIllustrationReferenceLibrary.swf"));
movieLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, movieLoaded_fn);
function movieLoaded_fn(e:Event): void {
movieContainer = movieLoader.content as MovieClip;
addChild(movieContainer);
movieContainer.x = 100;
}
Type the code below starting at the next line in the AS3 editor to create four buttons (red, yellow, green and blue) that, when pressed, will place the animation, remove the animation, play the animation or stop the animation.
var myButton:MovieClip = new MovieClip();
myButton.graphics.lineStyle(4);
myButton.graphics.beginFill(0xFF0000);
myButton.graphics.drawRect(10, 50, 50, 20);
myButton.graphics.endFill();
addChild(myButton);
myButton.addEventListener(MouseEvent.CLICK, callFunction_fn);
function callFunction_fn(e:MouseEvent): void {
removeChild(movieContainer);
};
var myButton1:MovieClip = new MovieClip();
myButton1.graphics.lineStyle(4);
myButton1.graphics.beginFill(0xFFFF00);
myButton1.graphics.drawRect(10, 100, 50, 20);
myButton1.graphics.endFill();
addChild(myButton1);
myButton1.addEventListener(MouseEvent.CLICK, callFunction2_fn);
function callFunction2_fn(e:MouseEvent): void {
addChild(movieContainer);
};
var myButton2:MovieClip = new MovieClip();
myButton2.graphics.lineStyle(4);
myButton2.graphics.beginFill(0x00FF00);
myButton2.graphics.drawRect(10, 150, 50, 20);
myButton2.graphics.endFill();
addChild(myButton2);
myButton2.addEventListener(MouseEvent.CLICK, callFunction3_fn);
function callFunction3_fn(e:MouseEvent): void {
movieContainer.stop();
};
var myButton3:MovieClip = new MovieClip();
myButton3.graphics.lineStyle(4);
myButton3.graphics.beginFill(0x0000FF);
myButton3.graphics.drawRect(10, 200, 50, 20);
myButton3.graphics.endFill();
addChild(myButton3);
myButton3.addEventListener(MouseEvent.CLICK, callFunction4_fn);
function callFunction4_fn(e:MouseEvent): void {
;
movieContainer.play();
};
Copy and paste the code to ensure that there are no syntax errors and that the Play and Remove Animations program works correctly.
var movieContainer:MovieClip;
var movieLoader:Loader = new Loader();
movieLoader.load(new URLRequest("MasterIllustrationReferenceLibrary.swf"));
movieLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, movieLoaded_fn);
function movieLoaded_fn(e:Event): void {
movieContainer = movieLoader.content as MovieClip;
addChild(movieContainer);
movieContainer.x = 100;
}
var myButton:MovieClip = new MovieClip();
myButton.graphics.lineStyle(4);
myButton.graphics.beginFill(0xFF0000);
myButton.graphics.drawRect(10, 50, 50, 20);
myButton.graphics.endFill();
addChild(myButton);
myButton.addEventListener(MouseEvent.CLICK, callFunction_fn);
function callFunction_fn(e:MouseEvent): void {
removeChild(movieContainer);
};
var myButton1:MovieClip = new MovieClip();
myButton1.graphics.lineStyle(4);
myButton1.graphics.beginFill(0xFFFF00);
myButton1.graphics.drawRect(10, 100, 50, 20);
myButton1.graphics.endFill();
addChild(myButton1);
myButton1.addEventListener(MouseEvent.CLICK, callFunction2_fn);
function callFunction2_fn(e:MouseEvent): void {
addChild(movieContainer);
};
var myButton2:MovieClip = new MovieClip();
myButton2.graphics.lineStyle(4);
myButton2.graphics.beginFill(0x00FF00);
myButton2.graphics.drawRect(10, 150, 50, 20);
myButton2.graphics.endFill();
addChild(myButton2);
myButton2.addEventListener(MouseEvent.CLICK, callFunction3_fn);
function callFunction3_fn(e:MouseEvent): void {
movieContainer.stop();
};
var myButton3:MovieClip = new MovieClip();
myButton3.graphics.lineStyle(4);
myButton3.graphics.beginFill(0x0000FF);
myButton3.graphics.drawRect(10, 200, 50, 20);
myButton3.graphics.endFill();
addChild(myButton3);
myButton3.addEventListener(MouseEvent.CLICK, callFunction4_fn);
function callFunction4_fn(e:MouseEvent): void {
;
movieContainer.play();
};
Click "Test Movie" in the Control menu to play the Play and Remove Animations program. Observe that the animation that you previously created (titled "MasterIllustrationReferenceLibrary.swf") is removed from the stage when the red button is activated, it's placed back on the stage when the yellow button is activated, it stops playing when the green button is activated and it begins playing again when the blue button is activated.