Actionscript Samples

 
Navigating the Timeline

Stop the timeline

stop();

Play the timeline play();
Play from frame 10 on the timeline gotoAndPlay(10);
Stop the timeline on frame 20 gotoAndStop(20);
Go to "Scene 5" and play from frame 1 gotoAndPlay("Scene 5", 1);
Go to "Scene 3" and stop on frame 30 gotoAndStop("Scene 3", 30);
   
Scripting Buttons
Go to frame 10 on release of a button

on (release) {
gotoAndplay(10);
}

Go to a URL on a button rollover

on (rollOver) {
getURL ("http://karlcleveland.com");
}

Play the timeline on button press or the pressing of the "p" key on the keyboard on (press, keyPress "p") {
play();
}
Scripting a button instance to stop the timeline on frame 20 using a frame action

myButtonInstanceName.onRelease = function () {
gotoAndStop(20);
}

   
Movieclips
Play from frame 5 of the movieclip "myClipName" _root.myClipName.gotoAndPlay(5);
Stop on frame 10 of the movieclip "myClipName2" that is inside the movieclip "myClipName1" _root.myClipName1.myClipName2.gotoAndStop(10);
Load a .swf movie into the movieclip "myClipName" _root.myClipName.loadMovie ("myMovieName.swf");
   
Sound
Loading and starting an external mp3 sound file

var my_sound:Sound = new Sound();
// creates sound object
my_sound.loadSound("trackname.mp3",true);
// loads track and streams
my_sound.start();
//starts the sound

Stopping a sound my_sound.stop();
Stopping all sounds stopAllSounds();
   
Video
Using a video object on the stage to play an external .flv video file

var nc:NetConnection = new NetConnection();
nc.connect(null);
var ns:NetStream = new NetStream(my_nc);
myVideo.attachVideo(ns);
// my_video is a Video object on the Stage
ns.play("myVideo.flv");

Scripting a play/pause button for the video above

on (release) {
ns.pause();
}
Scripiting a rewind button for the video above on (release) {
ns.seek(0);
}

Tracing a possible cuepoint

 

Using cuepoints to play a movieclip instance (called "myMovieClip") that is on the stage

 

_root.onMouseDown=function(){
trace(myVideo.playheadTime);
}

myObj=new Object();

myObj.cuePoint=function(p){
trace("received sync cue point named: "+ p.target.name);
myMovieClip.gotoAndPlay(p.target.name);
}

myVideo.addEventListener("cuePoint", myObj);

   
FS Commands for Projector Files
Make the screen size fullscreen fscommand("fullscreen", "true");
Allow the movie to scale to the screen size fscommand("allowscale", "true");
Don't allow the movie to scale fscommand("allowscale", "false");
Script for a "quit" or "exit" button

on (release) {
fscommand("quit");
}