Presentation is loading. Please wait.

Presentation is loading. Please wait.

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

Similar presentations


Presentation on theme: "Flash: ActionScript review & Controlling Sound Presentation by Mindy McAdams Edited for JOMC 187, UNC-Chapel Hill by Laura Ruel."— Presentation transcript:

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

2 ActionScript (so far) In the beginning…  stop();  play();  gotoAndStop( " someframelabel " );  gotoAndPlay( " otherframelabel " ); The script can be written on a button or on a frame

3 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 }

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

5 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 " ;

6 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 " ;

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

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

9 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 }

10 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”

11 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

12 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.

13 Variables in Sound Lesson Reserved words Syntactic keywords Future reserved words

14 Variables in Sound Lesson After we have declared a variable (with var), we can use it to do things -- rather like an instance name cooltune.start(0, 0); cooltune.stop(); These are the basics of audio in Flash (We’ll get back to this shortly)

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

16 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

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

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

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

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

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

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

23 ActionScript basics From the beginning…  stop();  play();  gotoAndStop( " someframelabel " );  gotoAndPlay( " otherframelabel " ); You will use these in almost every Flash movie.

24 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

25 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


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

Similar presentations


Ads by Google