Action Scripting | Basics | Scripting with Labels part 1 and part 2 | Scripting with Buttons | A Quick Look | Filters and Blends | Examples

Buttons with the scripts in the Actions Layer
buttonName.onRelease = function(){
gotoAndPlay("frameLabel");
};
Buttons for sound
buttonName.onRelease = function(){
mySound = new Sound();
mySound.loadSound("thesong.mp3", true);
mysound.start();
};
Buttons for sound with a stop all sounds added

buttonName.onPress = function(){
stopAllSounds();
};
buttonName.onRelease = function(){
mySound = new Sound();
mySound.loadSound("thesong.mp3", true);
mysound.start();
};

Controll sounds of movie clips

The Sound class allows volume and panning control of individual sounds in Flash. In the section of our movie where variables are declared, we'll create two instances of the Sound class and associate them with our respective sound movieclips:

var snoresound:Sound = new Sound(greenbean_mc);
snoresound.setVolume(50);

To add a sound on/off control that turns all sound in the movie on and off, create a Sound instance that's associated with the main timeline and set its volume to 0 or 100. With a sound control named mute_mc, this code in frame 1 will make it act as a toggle to mute and unmute all sound in the movie (including that in greenbean_mc and vegas_mc in the example above):

var allsound:Sound = new Sound(this);
mute_mc.onRelease = function() {
if (allsound.getVolume() == 100) {
allsound.setVolume(0);
} else {
allsound.setVolume(100);
}
};

Streaming Sound
mySound = new Sound();
mySound.loadSound("thesong.mp3", true);
mysound.start();
Looping a Streaming MP3 track = new Sound();
track.loadSound("theSong.mp3", false);
function StartPlayback() {
track.start(0,999); // 0=start position in seconds; 999=loop count
}
track.onLoad = StartPlayback;
Random sounds

buttonName.onRelease = function() {
//here is where you name the mp3 files
img = ["1st.mp3", "2nd.mp3", "3rd.mp3", "4th.mp3", "Violin.mp3"];
mySound = new Sound();
//here is where you load a random sound from above
mySound.loadSound(img[Math.floor(Math.random()*(5-1))], true);
//you need to start it
mysound.start();
};

Buttons to load SWF's buttonName.onRelease = function(){
loadMovie("file.swf", 10);
//10 is the level
};
Buttons to unload SWF's buttonName.onRelease = function(){
unloadMovie(10);
//10 is the level
};
Random Images

buttonName.onRelease = function() {
//here is where you name the image files
img = ["one.jpg", "two.jpg", "three.jpg", "four.jpg"];
//here is where you load a random image from above
loadMovie(img[Math.floor(Math.random()*(5-1))], aBlankMovieClipSymbolInstanceName);
};

Mouse to control opacity for four images / videos - don't forget to add a frame 2 to go back and play frame 1
//Creates a new movie clip on the '_root'
//timeline which is named 'script_clip'
_root.createEmptyMovieClip("script_clip", 0);
script_clip.onLoad = function() {
//Makes variable to store inertia.
mosx = 0;
//Makes variable to store inertia.
mosy = 0;
};
//Starts a movie clip loop that executes
//the code everytime the play head enters
//a frame and this only works in Flash MX
script_clip.onEnterFrame = function() {
//Takes 'mosx' and subtracts by the _xmouse mouse position to yield the difference.
difx = mosx - _root._xmouse;
//Takes 'mosy' and subtracts by the _ymouse mouse position to yield the difference.
dify = mosy - _root._ymouse;
//Subtracts the total of the _xmouse position and 'mosx' and 8 determines the speed of the effect.
mosx -= difx / 8;
//Subtracts the total of the _ymouse position and 'mosy' and 8 determines the speed of the effect.
mosy -= dify / 8;
//Used to control the _alpha setting of 'graphic1' with dependency of the mouse position and inertia.
_root.graphic1._alpha = (mosx / 4) - (mosy / 4);
//Used to control the _alpha setting of 'graphic2' with dependency of the mouse position and inertia.
_root.graphic2._alpha = 100 - (mosx / 4) - (mosy / 4);
//Used to control the _alpha setting of 'graphic3' with dependency of the mouse position and inertia.
_root.graphic3._alpha = (mosy / 4) - 100 + (mosx / 4);
//Used to control the _alpha setting of 'graphic4' with dependency of the mouse position and inertia.
_root.graphic4._alpha = (mosy / 4) - (mosx / 4);
};

Adding a Key Listener on a button

download

on (release) {
getURL("_______");
}
on (keyPress "x") {
getURL("_______");
}
Enable buttons
buton2.enabled = false;
Key Listeners for keyboard keys

The keycodes. Wait for it , it is a long list:

Letters
A - 65
B - 66
C - 67
D - 68
E - 69
F - 70
G - 71
H - 72
I - 73
J - 74
K - 75
L - 76
M - 77
N - 78
O - 79
P - 80
Q - 81
R - 82
S - 83
T - 84
U - 85
V - 86
W - 87
X - 88
Y - 89
Z - 90

Numbers
0 - 48
1 - 49
2 - 50
3 - 51
4 - 52
5 - 53
6 - 54
7 - 56
8 - 57
9 - 58
Here is an example of a keyListener and how you can use the ascii keycodes in Flash Actionscript programming:

// key listener..

keyListener = new Object(); // make key listener object
// this function gets triggered whenever a key is pressed
keyListener.onKeyDown = function() {
var keyCode = Key.getCode(); // get the key code

if (keyCode == 87) { // W
// do something
blah_mc._alpha -= 10;
}
} else if (keyCode == 83) { // S
// move car left
car_mc._x -= 10;
}
} else if (keyCode == 68) { // D
car_mc.gotoAndStop(3);
}
};
Key.addListener(keyListener); // notify Key object about your listener

Controlling timelines of movie clips - example
buttonName.onRelease = function(){
MovieClipSymbolInstanceName.gotoAndPlay("frameLabel");
}
Button Visibility
but1._visible = true;
A Flash MP3 Player
lots of scripts here including arrays
Loading External Images

load Movie("ad_1.jpg",loader);

//ad_1.jpg is an image in the folder, loader is a blank movie symbol in Flash MX

Loading External Images Randomly

example

download

Loading External Images Randomly from a button

Download

Random explosion(you need to make a "ball" movie clip with linkage)
particle = function () {
// PURPOSE: defines the particle object
//
// initialize properties
this.speedX = (Math.random()*8)-4;
this.speedY = (Math.random()*8)-4;
this.lowX = 0;
this.lowY = 0;
this.highX = 550;
this.highY = 400;
this._x = 200;
this._y = 200;
// END initialize properties
//
// Define events
this.onEnterFrame = function() {
if (this._x<this.lowX) {
this.speedX = Math.random()*4;
} else if (this._x>this.highX) {
this.speedX = -Math.random()*4;
}
if (this._y<this.lowY) {
this.speedY = Math.random()*4;
} else if (this._y>this.highY) {
this.speedY = -Math.random()*4;
}
this._x += this.speedX;
this._y += this.speedY;
};
this.onPress = function() {
this.speedX = 0;
this.speedY = 0;
};
// END define events
};
//
// main code
particle.prototype = new MovieClip();
for (i=0; i<100; i++) {
_root.attachMovie("ball", "ball"+i, 1000+i);
particle.apply(_root["ball"+i]);
}
// END main code

Scrolling Content

part 1 download

part 2 download

part 3 download

//This is in three parts
//Attach the 1st part to the content object
onClipEvent (load) {
var direction = 0;
var ySpeed = 10;
var minY = -320;
var maxY = 6;
}
onClipEvent (enterFrame){
this._y += ySpeed*direction;
if (this._y < minY) this._y = minY;
if (this._y > maxY) this._y = maxY;
}

//Attach the second part to the up
//button
on (press) {
content.direction = +1;
}
on (release, releaseOutside) {
content.direction = 0;
}

//Attach the third part to the down
//button
on (press) {
content.direction = -1;
}
on (release, releaseOutside) {
content.direction = 0;
}

Moving a Movie Clip on the stage with the arrow keys
//attach this script to the clip
onClipEvent (load) {
speed=3;
}
onClipEvent (enterFrame) {
if (key.isDown(key.RIGHT)) {
_x+=speed;
} else if (key.isDown(key.LEFT)) {
_x-=speed;
}
if (key.isDown(key.UP)) {
_y-=speed;
} else if (key.isDown(key.DOWN)) {
_y+=speed;
}
}
Looping FLV's
download

It is a three frame process on the actions layer. The third frame loops back to the second frame.

A second layer is added with an instance of a FLV player. Remember to name the instance.

Song Structure

Chord Guide

Exporting a video

Student Work

DVD Techniques

MM Template

How to Submit your song

Flash Help

 

Garage Band Demo

Deck | SE 16

Launch QT Player

Load an MP4

TI:ME Article

Practice

Games

Photoshop Help

Sound Loops

Digital Performer

Reason Tutorial

Soundtrack Tutorial

Garage Band tips

How to Become A Rock Star

Exporting your Garageband tune

Pictures

 

Imagination and Time
*

  • C ave control of, or do you? Can you figure out how to play the sounds one at a time?

Dial Volume
*

  • This dial will control the volume of the song "Suite for Guitar". It rotates with the mouse.

There is nothing to see here
*

  • There is nothing to see here. Well, there is if you spend the time looking. What time is it? Do you hear anything?
Mixer 2
*
  • This mixer has 8 channels. You control which sounds you want to hear.

Draw Pad
*

  • Enjoy drawing on the screen and listening to music.

TV IN STONE
*

  • This television does not have any picture, but it does have some neat sounds.

Pentatonic rainbow
*

  • Watch the name fade away in rainbow colors and reveal a pentatonic melody maker

Sound Mixer
*

  • This sound mixer lets you mix the individual parts of the beat.

Let's Fade
*

  • This fades between videos using the mouse
Rotation
*
  • This simple Flash script lets you adjust the sound with + and - buttons
Movie Maker
  • This Flash file makes movies. The script is massive.
Scroll with the mouse
*
  • This script creates a moving menu that scrolls with the mouse

Sync1
*

  • This file shows how you can sync music together - being able to mute and unmute individual tracks
  • script
Sync2
*
  • This file shows how you can sync music together - being able to mute and unmute individual tracks. This one includes animation.
Sync3
*
  • This file shows how you can sync music together - being able to mute and unmute individual tracks. This one includes animation.
Mouse
*
  • This file is a simple moues hide with a rotation effect
  • script
Drums
*
  • This is a complex percussion animation that allows the user to create beats
Fade
*
  • This Scrolls with fading mouse controll
  • script
Reflection
*
  • Reflection plays a pentatonic song with each ripple
  • script
Bounce
*
  • This man bounces!
  • This is very funny! But seriously, this piece is built well and shows how cleaver anamation and sound can be used.It was built for a Sweadish TV show.
Hot Air
*
  • How much Hot Air do you have?
Sound Wave 1
*
  • What does your voice look like?
Sound Wave 2
*
  • Now what does your voice look like?
Where is the that fly?
*
  • This fly moves randomly
What a mouth
*
  • Hey, he says what I AM SAYING!
Dumb Drummer
*
  • How many drummers does it take to...

Adding Dynamic text
(Make a button and a dynamic text field(i.e. btn1 and message))

btn1.onRollOver = function() {
message.text = "Hello There";
};
btn1.onRollOut = function() {
message.text = " ";
};
btn2.onRollOver = function() {
message.text = "Go Away";
};
btn2.onRollOut = function() {
message.text = " ";
};
How about this?

smbclient -M NAS###### -U

352020 - SH

352287 - Multi

330134 - PB@NAI

jumping between layers

//set the alpha for each movie clip
setProperty("clip1", _alpha, "0");
setProperty("clip2", _alpha, "0");
setProperty("clip3", _alpha, "0");
//put this in the actions layer

//part two
//put this in the buttons
on (release) {
setProperty("clip1", _alpha, "100");
setProperty("clip2", _alpha, "0");
setProperty("clip3", _alpha, "0");
}

advanced sound

part 1

part 2

//part one - the start button
on (release) {
one1 = new Sound(pic1);
two1 = new Sound(pic2);
three1 = new Sound(pic3);
one1.attachSound("one");
two1.attachSound("two");
three1.attachSound("three");
one1.start(0,99);
two1.start(0,99);
three1.start(0,99);
on1._visible = false;
off._visible = true;
_root.move1.gotoAndPlay(2);
_root.move2.gotoAndPlay(2);
_root.move3.gotoAndPlay(2);
gotoAndStop(2);
}

//part two - each button
on (release){
_root.one1.setVolume(0);
}

Random song for a site

Download

// attach this to a frame
// you need a movie clip called loader
//the sound swf's are visually empty
adList = new Array(
"sound/c-sharp.swf",
"sound/b-flat.swf",
"sound/e-flat.swf"
);
i = random(adList.length);
loadMovie(adList[i], loader);

Using Variables with buttons

If a global variable is assigned(doorkey) in the flash file, that can be used to effect the function of a button. The rest of the script uses the dynamic text mentioned eariler.

//assign the global variable
doorkey = "false";

//have a button change the variable property
on (release) {
doorkey = "true";
}

//this is where the button is controlled by the variable
on (release) {
if (doorkey == "true") {
gotoAndPlay("Scene 17", 1);
} else {
message.text = "Locked";
}
}

Using External text files

The swf

the Fla

http://www.kirupa.com/developer/mx/advanced.htm
This site has some great links and tutorials to use in Flash.
http://www.gurusnetwork.com
Another tutorial site.
http://www.webthang.co.uk/
More Flash Tutorials

 

The FLA

This creates a random number using the switch and case functions
The FLA
fade sound
camera zoom - this fla zooms the stage around using a simple motion tween

thefla

the script

Pre-built Flash Templates
Click on the picture to view
Click on the name to download