flash: controlling sound

26
Flash: Controlling Sound Presentation by Mindy McAdams

Upload: karly-mcintyre

Post on 30-Dec-2015

28 views

Category:

Documents


0 download

DESCRIPTION

Flash: Controlling Sound. Presentation by Mindy McAdams. ActionScript (so far). From Lessons 1 through 7: stop(); play(); gotoAndStop( " someframelabel " ); gotoAndPlay( " otherframelabel " ); The script can be written on a button or on a frame. ActionScript for buttons. - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Flash: Controlling Sound

Flash: Controlling Sound

Presentation by Mindy McAdams

Page 2: Flash: Controlling Sound

ActionScript (so far)

From Lessons 1 through 7: stop(); play(); gotoAndStop("someframelabel"); gotoAndPlay("otherframelabel");

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

Page 3: Flash: Controlling Sound

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: Controlling Sound

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();

_parent.stop();

Page 5: Flash: Controlling Sound

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): n = 27; myColor = "orange";

Page 6: Flash: Controlling Sound

ActionScript 2.0 variables

Not in the book: AS 2.0 would like script to be more

formal in style Examples of the initial declaration of

variables in AS 2.0: var n = 27; var myColor = "orange";

Page 7: Flash: Controlling Sound

ActionScript 2.0 variables

In fact, AS 2.0 would like things to be EVEN MORE formal:

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: Controlling Sound

Selecting ActionScript version

To make life easy, when following the book, you can simply change the Publish Settings to AS 1.0

But eventually, people will use AS 2.0 for everything

Page 9: Flash: Controlling Sound

ActionScript variables

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

You can do that in AS 1.0 or 2.0 However – we need not use strict data

typing (:Number, :String, etc.)

Page 10: Flash: Controlling Sound

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 11: Flash: Controlling Sound

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 12: Flash: Controlling Sound

Variables in Lesson 8 (Sound)

The book says: x = new Sound();

Here the variable is x – and we are declaring it for the first time

So to be more formal and correct:var x = new Sound();

Only the first time you use x in a movie – do not write var after the first appearance of the variable

Page 13: Flash: Controlling Sound

Variables in Lesson 8 (Sound)

A variable name can be any word (except the “reserved words”; see pp. 479 - 480)

It’s common to use letters such as x, y, and z as names of variables

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

Page 14: Flash: Controlling Sound

Variables in Lesson 8

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

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

Page 15: Flash: Controlling Sound

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);

x.attachSound("crossroads");

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

Page 16: Flash: Controlling Sound

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: Controlling Sound

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

x.stop();

x.start(0, 0);

Page 18: Flash: Controlling Sound

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: -

x.start(0, 0);

x.start(0, 100);

x.start(20, 0);

Page 19: Flash: Controlling Sound

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 position

var p;p = Math.floor(x.position/1000);

Page 20: Flash: Controlling Sound

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(x.position/1000);

Page 21: Flash: Controlling Sound

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(x.position/1000);x.start(p, 0);

Page 22: Flash: Controlling Sound

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

x.setVolume(0);

x.setVolume(100);

Page 23: Flash: Controlling Sound

ActionScript basics

From Lessons 1 through 7: stop(); play(); gotoAndStop("someframelabel"); gotoAndPlay("otherframelabel");

You will use these in almost every Flash movie

Page 24: Flash: Controlling Sound

ActionScript for audio (basics)

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

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

Page 25: Flash: Controlling Sound

ActionScript/audio (advanced)

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

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

Page 26: Flash: Controlling Sound

Flash: Controlling Sound

The End

Presentation by Mindy McAdams

> Flash Journalism: Lesson 8