flash: actionscript review & controlling sound presentation by mindy mcadams edited for jomc...

25
Flash: ActionScript review & Controlling Sound Presentation by Mindy McAdams Edited for JOMC 187, UNC-Chapel Hill by Laura Ruel

Upload: lucas-jenkins

Post on 08-Jan-2018

227 views

Category:

Documents


0 download

DESCRIPTION

If script is on a button: on (release) { stuff here } Alternatively -- if a button has an instance name, you can put the script on the Timeline this way: rewind_btn.onRelease = function () { stuff here } ActionScript for buttons on (release) { stuff here } rewind_btn.onRelease = function () { stuff here }

TRANSCRIPT

Page 1: Flash: ActionScript review & Controlling Sound Presentation by Mindy McAdams Edited for JOMC 187, UNC-Chapel Hill by Laura Ruel

Flash: ActionScript review& Controlling Sound

Presentation by Mindy McAdams

Edited for JOMC 187, UNC-Chapel Hillby Laura Ruel

Page 2: Flash: ActionScript review & Controlling Sound Presentation by Mindy McAdams Edited for JOMC 187, UNC-Chapel Hill by Laura Ruel

ActionScript (so far)

In the beginning… stop(); play(); gotoAndStop("someframelabel"); gotoAndPlay("otherframelabel");

The script can be written on a button or on a frame

Page 3: Flash: ActionScript review & Controlling Sound Presentation by Mindy McAdams Edited for JOMC 187, UNC-Chapel Hill by Laura Ruel

If script is on a button:on (release) { stuff here }

Alternatively -- if a button has an instance name, you can put the script on the Timeline this way:rewind_btn.onRelease = function () { stuff here }

ActionScript for buttons

on (release) { stuff here }

rewind_btn.onRelease = function () { stuff here }

Page 4: Flash: ActionScript review & Controlling Sound Presentation by Mindy McAdams Edited for JOMC 187, UNC-Chapel Hill by Laura Ruel

If you need to make a movie clip stop playing (if the instance name is clouds_mc) from the main Timeline:

Or if the movie clip needs to tell the main Timeline to stop playing:

ActionScript & movie clips

clouds_mc.stop();

this._parent.stop();

Page 5: Flash: ActionScript review & Controlling Sound Presentation by Mindy McAdams Edited for JOMC 187, UNC-Chapel Hill by Laura Ruel

New, exciting ActionScript

What is a variable? A kind of container for data Each variable has a name (static) Each variable has a value (dynamic)

Examples of variables (name, left; and value, right): var n = 27; var myColor = "orange";

Page 6: Flash: ActionScript review & Controlling Sound Presentation by Mindy McAdams Edited for JOMC 187, UNC-Chapel Hill by Laura Ruel

ActionScript 2.0 variables

AS 2.0 likes script to be as specific as possible.

Examples of the initial declaration of variables in AS 2.0: var n = 27; var myColor = "orange";

Page 7: Flash: ActionScript review & Controlling Sound Presentation by Mindy McAdams Edited for JOMC 187, UNC-Chapel Hill by Laura Ruel

ActionScript 2.0 variables

In AS2, the you can be even more specific and “tell Flash” the type of variable you are declaring:

Examples of the initial declaration of variables in AS 2.0, including “strict data typing”: var n:Number = 27; var myColor:String = "orange";

Page 8: Flash: ActionScript review & Controlling Sound Presentation by Mindy McAdams Edited for JOMC 187, UNC-Chapel Hill by Laura Ruel

ActionScript variables

We always should formally declare variables: var n = 27; var myColor = "orange";

Page 9: Flash: ActionScript review & Controlling Sound Presentation by Mindy McAdams Edited for JOMC 187, UNC-Chapel Hill by Laura Ruel

ActionScript variables

How does a variable work? var n = 27; n = n + 1; if (n == 28) { stuff here }

Another example: var myColor = "orange"; if (myColor != " blue")

{ stuff here }

Page 10: Flash: ActionScript review & Controlling Sound Presentation by Mindy McAdams Edited for JOMC 187, UNC-Chapel Hill by Laura Ruel

ActionScript operators

== “is equivalent to” != “is NOT equivalent to” > “is greater than” < “is less than” >= “is greater than or equal to” <= “is less than or equal to”

Page 11: Flash: ActionScript review & Controlling Sound Presentation by Mindy McAdams Edited for JOMC 187, UNC-Chapel Hill by Laura Ruel

Variables in Lesson 8 (Sound)

var cooltune = new Sound(); Here the variable is cooltune – and

we are declaring it for the first time Only the first time you use cooltune

in a movie – do not write var after the first appearance of the variable

Page 12: Flash: ActionScript review & Controlling Sound Presentation by Mindy McAdams Edited for JOMC 187, UNC-Chapel Hill by Laura Ruel

Variables in Sound Lesson A variable name can be any word (except

the “reserved words”; ie, the ones that turn blue when typing your script. (See next slide for list.)

It’s common to use letters such as w, and z as names of variables. Avoid using “x” and “y” as they can be used in other contexts for coordinates.

It’s also common to use “camel case” in the name -- e.g. mySound, theMusic, etc.

Page 13: Flash: ActionScript review & Controlling Sound Presentation by Mindy McAdams Edited for JOMC 187, UNC-Chapel Hill by Laura Ruel

Variables in Sound Lesson Reserved words Syntactic keywords

Future reserved words

Page 14: Flash: ActionScript review & Controlling Sound Presentation by Mindy McAdams Edited for JOMC 187, UNC-Chapel Hill by Laura Ruel

Variables in Sound Lesson

After we have declared a variable (with var), we can use it to do things -- rather like an instance namecooltune.start(0, 0);cooltune.stop();

These are the basics of audio in Flash (We’ll get back to this shortly)

Page 15: Flash: ActionScript review & Controlling Sound Presentation by Mindy McAdams Edited for JOMC 187, UNC-Chapel Hill by Laura Ruel

Bringing sound into the FLA

The only script difference between the two methods for the Sound object concerns how you associate your audio file with your variable:x.attachSound("crossroads");

… or … x.loadSound("rainforest.mp3",

true);

cooltune.attachSound("crossroads");

cooltune.loadSound("rainforest.mp3", true);

Page 16: Flash: ActionScript review & Controlling Sound Presentation by Mindy McAdams Edited for JOMC 187, UNC-Chapel Hill by Laura Ruel

External MP3 files (loadSound)

To load an external audio file, the file MUST BE in the MP3 file format

Also, the file must have a sampling rate of one of these three values (on pp. 216 – 217): 11.025 kHz (doesn’t sound great) 22.05 kHz (usually best choice) 44.1 kHz (CD quality; big file size)

Otherwise, you will have distorted sound

Page 17: Flash: ActionScript review & Controlling Sound Presentation by Mindy McAdams Edited for JOMC 187, UNC-Chapel Hill by Laura Ruel

Starting and stopping sound

To stop a Sound object represented by the variable name x:x.stop();

(Exactly like stopping a movie clip) To play a Sound object (from the

beginning):x.start(0, 0);

Script can be on a button or on a frame

cooltune.stop();

cooltune.start(0, 0);

Page 18: Flash: ActionScript review & Controlling Sound Presentation by Mindy McAdams Edited for JOMC 187, UNC-Chapel Hill by Laura Ruel

Options for starting sound

This will start the sound from the beginning AND play it only once: -

This will start the sound from the beginning and loop it 100 times: -

This will start the sound 20 seconds after the beginning and play it only once:

cooltune.start(0, 0);

cooltune.start(0, 100);

cooltune.start(20, 0);

Page 19: Flash: ActionScript review & Controlling Sound Presentation by Mindy McAdams Edited for JOMC 187, UNC-Chapel Hill by Laura Ruel

Pausing sound

Before you pause an audio file, you must determine how much has already played

Then you will be able to start it (later) from the same point

This property is called positionvar p;p = Math.floor(x.position/1000);

Page 20: Flash: ActionScript review & Controlling Sound Presentation by Mindy McAdams Edited for JOMC 187, UNC-Chapel Hill by Laura Ruel

Pausing sound (2)

Say the sound file had already played for 5.2 seconds (5,200 milliseconds)

This script will get the number 5,200 and divide it by 1,000:

Then it will round down the result to a whole number (not a decimal)

Result: p = 5

p = Math.floor(cooltune.position/1000);

Page 21: Flash: ActionScript review & Controlling Sound Presentation by Mindy McAdams Edited for JOMC 187, UNC-Chapel Hill by Laura Ruel

Pausing sound (3)

If you have the value of p, you can use that value to restart the audio file at the correct point after it has been paused: P x

If the value of p were 5, then the audio would immediately start playing from the point 5 seconds into the file.

p = Math.floor(cooltune.position/1000);x.start(p, 0);

Page 22: Flash: ActionScript review & Controlling Sound Presentation by Mindy McAdams Edited for JOMC 187, UNC-Chapel Hill by Laura Ruel

Adjusting the volume

If all you need to do is mute the audio (while it continues to play): -

If you then need to return the audio to the maximum volume: -

The volume range is exactly 0 to 100

cooltune.setVolume(0);

cooltune.setVolume(100);

Page 23: Flash: ActionScript review & Controlling Sound Presentation by Mindy McAdams Edited for JOMC 187, UNC-Chapel Hill by Laura Ruel

ActionScript basics

From the beginning… stop(); play(); gotoAndStop("someframelabel"); gotoAndPlay("otherframelabel");

You will use these in almost every Flash movie.

Page 24: Flash: ActionScript review & Controlling Sound Presentation by Mindy McAdams Edited for JOMC 187, UNC-Chapel Hill by Laura Ruel

ActionScript for audio (basics)

From Sound Lesson (“tunes” can be any name): var tunes = new Sound(); tunes.attachSound(); tunes.loadSound(); tunes.start(0, 0); tunes.stop();

You will use these to control sound in any Flash movie that requires it

Page 25: Flash: ActionScript review & Controlling Sound Presentation by Mindy McAdams Edited for JOMC 187, UNC-Chapel Hill by Laura Ruel

ActionScript/audio (advanced)

From Lesson 8 (“tunes” and “p”can be any names): var tunes = new Sound(); var p = 0; p = Math.floor(x.position/1000); tunes.start(p, 0); tunes.setVolume(0); tunes.setVolume(100);

You will use these to control sound in conjunction with buttons in the Flash movie