ARTV 1303: Basic Animation

D.Carter ~ Topics

Actionscript 3.0 examples

// Stop and play main timeline. Put script in frame 1. Be sure fish is a button with instance name "fish_btn".

//this is a comment and does not compile

function playMovie(event:MouseEvent):void
{
play();
}

function stopMovie(event:MouseEvent):void
{
stop();
}

fish_btn.addEventListener(MouseEvent.MOUSE_OVER, stopMovie);
fish_btn.addEventListener(MouseEvent.MOUSE_OUT, playMovie);

// Stop and play a movie clip named man_mc. Change Movie Clip location. Put script in Frame 1. Use button with instance name "man_btn".

function playMovie(event:MouseEvent):void
{
man_mc.play();
}


function stopMovie(event:MouseEvent):void
{
man_mc.stop();
man_mc.x = 222;
man_mc.y = 222;
}

man_btn.addEventListener(MouseEvent.MOUSE_OVER, stopMovie);
man_btn.addEventListener(MouseEvent.MOUSE_OUT, playMovie);

//launching a URL


//below is a variable named "fish_req" used to identify the URL
var fish_req:URLRequest = new URLRequest("http://home.flash.net/~dcarter/");

//this function called "fish" goes to the URL identified by the variable
function fish(event:MouseEvent):void
{
navigateToURL(fish_req, "_blank");
}

//listens for the button to be clicked. Calls the fish function
fish_btn.addEventListener(MouseEvent.CLICK, fish);

//The following script is used to load external .swf files into the current .swf file. The external files are located in folders named "fish1", "fish2",fish3".
//This script goes in the first frame of the file "fishTank.swf". Use a file with two frames. Put a stop in both frames.

stop();

//creates a new object for each fish
var myLoader:Loader = new Loader();
var myLoader1:Loader = new Loader();
var myLoader2:Loader = new Loader();

//this listens for the button click
fish.addEventListener(MouseEvent.CLICK, buttonClick);

//this function is called from the mouse click on the button
function buttonClick(event:MouseEvent):void
{
this.myLoader.load(new URLRequest("fish1/fish.swf"));
this.myLoader1.load(new URLRequest("fish2/fish.swf"));
this.myLoader2.load(new URLRequest("fish3/fish.swf"));
//the script below moves the playback head to frame 2 after the fish are loaded.
gotoAndStop(2);

}

//this code is needed to display the objects on the screen
addChild(myLoader)
addChild(myLoader1)
addChild(myLoader2)

//The following script is used for navigation. The buttons need the same instance name as the frame label thay are linking to. Put this script in frame 1.

stop();

function changeLabel(event:MouseEvent):void
{
gotoAndStop(event.target.name);
}

home.addEventListener(MouseEvent.CLICK, changeLabel);
about.addEventListener(MouseEvent.CLICK, changeLabel);
text.addEventListener(MouseEvent.CLICK, changeLabel);
art.addEventListener(MouseEvent.CLICK, changeLabel);
contact.addEventListener(MouseEvent.CLICK, changeLabel);
animation.addEventListener(MouseEvent.CLICK, changeLabel);

 

//Part 1. Input text and dynamic text. This script goes in frame 1. Be sure to set a textfield to "Input" and give it an instance name of "name_txt". Create a button and give it an instance name of "enter_btn"

var nameString:String;
enter_btn.addEventListener(MouseEvent.CLICK,onClick);

function onClick(event:MouseEvent):void
{
if(name_txt.text!= null)
{nameString = name_txt.text;
gotoAndStop(2);
}
}
stop();

//Part 2. Next add a textfield in frame 2. Be sure to set it to 'dynamic" and give it an instance name of "message_txt". Put the script below in Frame 2.

message_txt.text = "Welcome "+ nameString +". Thanks for visiting the Basic Animation Website.";