Sound in action script
This presentation is the property of its rightful owner.
Sponsored Links
1 / 29

Sound in Action Script PowerPoint PPT Presentation


  • 66 Views
  • Uploaded on
  • Presentation posted in: General

"The games of a people reveal a great deal about them.“ Marshall McLuhan. Sound in Action Script. Enhance animation and interactivity Engaging more user’s senses Establish the mood of the movie Use narration to accompany the story Give audible feedback to interactions

Download Presentation

Sound in Action Script

An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -

Presentation Transcript


Sound in action script

"The games of a people reveal a great deal about them.“

Marshall McLuhan

Sound in Action Script


Controlling sound

Enhance animation and interactivity

Engaging more user’s senses

Establish the mood of the movie

Use narration to accompany the story

Give audible feedback to interactions

Flash supports .WAV, .MP3, .AIF

Sound class controls sound

Start

Stop

Adjust sound volume

Stereo effect

Controlling sound


Controlling sound1

sound object

mySound=new Sound();

mySound.attachSound(“sound_name”);

mySound.start ( seconds offset, loops);

Seconds offsetnumber that determines how many seconds into the sound it should begin playing

(from the beginning 0, or from a later point)

Loopshow many times sound will play

No parametersFlash playes sound once from the start

Controlling sound


Controlling sound2

mySound.start ( 0, 5);

Plays sound from the beginning 5 times

mySound = new Sound();

mySound.attachSound("guitar");

startButton_btn.onRelease = function()

{

mySound.start(0,5);

}

stopButton_btn.onRelease = function()

{

mySound.stop();

}

Controlling sound


Modifying sounds

Flash allows to attach many sounds to the same sound object

Start function will play the most current sound attached

Volume control

setVolume()

Racing game- control the volume of the car engine sound as the cars pass by

Pan control - control of the output through the left or right speaker

setPan()

Pong game – control the left and right hit wall sounds from the appropriate sides

Modifying sounds


Modifying sounds1

setVolume(percentage of the full volume from 0 to 100)

100- maximum volume

0- silence

setPan(number from -100 to 100)

-100left speaker

100right speaker

0plays sound from both speakers equally

Modifying sounds


Modifying sounds 02soundobject pan volume fla

Open 02soundobject_pan_volume.fla from the Pickup folder

Modifying sounds – 02soundobject_pan_volume.fla


Modifying sounds 02soundobject pan volume fla1

Drag the instances of the volume, left, right, both buttons on the stage and name them:

volUp_btn

volDown_btn

leftSpeaker_btn

rightSpeaker_btn

bothSpeakers_btn

Modifying sounds – 02soundobject_pan_volume.fla


Modifying sounds2

volUp_btn.onRelease = function() {

mySound.setVolume(100);

}

volDown_btn.onRelease = function() {

mySound.setVolume(20);

}

leftSpeaker_btn.onRelease = function() {

mySound.setPan(-100);

}

rightSpeaker_btn.onRelease = function() {

mySound.setPan(100);

}

bothSpeakers_btn.onRelease = function() {

mySound.setPan(0);

}

Modifying sounds


Modifying sounds independently 03modify2sounds fla

Create separate sound objects with parameters that target specific movie clips

Sound objects will be applied to different movie clips so that

setVolume () and setPan () could control the sounds separately

Modifying sounds independently 03modify2sounds.fla


Modifying sounds independently 03modify2sounds fla1

clip1= _root.createEmptyMovieClip("clip1", 1);

clip2 = _root.createEmptyMovieClip("clip2", 2);

mySound1 = new Sound(clip1);

mySound2 = new Sound(clip2);

mySound1.attachSound("music1");

mySound2.attachSound("music2");

start1Button_btn.onRelease = function() {

mySound1.start(0, 1);

}

start2Button_btn.onRelease = function() {

mySound2.start(0, 1);

}

leftButton_btn.onRelease = function() {

mySound1.setPan(-100);

}

rightButton_btn.onRelease = function() {

mySound2.setPan(100);

}

Modifying sounds independently 03modify2sounds.fla


Transforming sounds 04soundtransform fla

More precise sound control

Switch left / right speakers and stereo / mono dynamically

setTransform ()

allows to set percentage of how much of the lefr /right channel will play through left / right speakers

Properties of the sound transform object

ll% value -how much of the left input plays in the left speaker

lr% value -how much of the right input plays in the left speaker

rr% value -how much of the right input plays in the right speaker

rl% value -how much of the left input plays in the right speaker

Transforming sounds 04soundtransform.fla


Transforming sounds 04soundtransform fla1

mySound = new Sound();

mySound.attachSound("conversation");

startButton_btn.onRelease = function()

{

mySound.start(0, 5);

}

transformButton_btn.onRelease = function()

{

mySoundTransform = new Object();

mySoundTransform.ll = 0;

mySoundTransform.lr = 100;

mySoundTransform.rl = 100;

mySoundTransform.rr = 0;

mySound.setTransform(mySoundTransform);

}

Transforming sounds 04soundtransform.fla


Transforming sounds 04soundtransform fla2

When we click Transform button Flash creates a generic object with properties (mySoundTrasnform.ll, mySoundTrasnform.lr, …)

to hold the sound transformation information.

This information then used by the setTransfrom ()

to change the distribution in the left and right speakers.

Transforming sounds 04soundtransform.fla


Dynamic sound control 05dynamicsound fla

Sets desired volume level or speaker control

draggable movie clip acting as a sliding controller

The position of the movie clip is correlated with volume parameter of the setVolume ()

slider_mc movie clip

groove_mc movie clip

Groove_mc will limit the motion of the draggable slider_mc

Dynamic sound control 05dynamicsound.fla


Dynamic sound control 05dynamicsound fla1

slider_mc.onPress = function()

{

this.startDrag(false,

_root.groove_mc._x,

_root.groove_mc._y - 100,

_root.groove_mc._x,

_root.groove_mc._y);

}

slider_mc.onRelease = function()

{

stopDrag();

}

Dynamic sound control 05dynamicsound.fla


Dynamic sound control 05dynamicsound fla2

slider_mc.onPress = function()

{

this.startDrag(false,

_root.groove_mc._x,

_root.groove_mc._y - 100,

_root.groove_mc._x,

_root.groove_mc._y);

}

When user presses the slider_mc, startDrag () lets the user drag the specified movie clip and limits the position of the clip according to parameters

Dynamic sound control 05dynamicsound.fla


Dynamic sound control 05dynamicsound fla3

.startDrag([lock, [left, top, right, bottom]])

Lock A Boolean value specifying whether the draggable movie clip is locked to the center of the mouse position ( true ), or locked to the point where the user first clicked on the movie clip ( false )

left , top , right , bottomValues relative to the coordinates of the movie clip's parent that specify a constraint rectangle for the movie clip.

Dynamic sound control 05dynamicsound.fla


Dynamic sound control 05dynamicsound fla4

slider_mc.onRelease = function()

{

stopDrag();

}

stopDrag() stops dragging

setVolume(100)

setVolume(0)

Dynamic sound control 05dynamicsound.fla


Dynamic sound control 05dynamicsound fla5

setVolume(100)

setVolume(0)

Correlates the y position of the slider_mc with the setVolume()

globalToLocal()converts the coordinates of the slider to coordinates relative to the groove

Dynamic sound control 05dynamicsound.fla


Dynamic sound control 05dynamicsound fla6

Dynamic sound control 05dynamicsound.fla


Dynamic sound control 05dynamicsound fla7

slider_mc.onMouseMove = function()

{

myPoint = new Object();

myPoint.x = this._x;

myPoint.y = this._y;

_root.groove_mc.globalToLocal(myPoint);

}

The current x position of the slider is assigned to myPoint.x

onMouseMoveprovides a good way to trigger volume change based on the slider position

The global coordinates of myPoint are changed to local coordinates of the groove movie clip

Dynamic sound control 05dynamicsound.fla


Dynamic sound control 05dynamicsound fla8

Link slider position to volume setting

myMusic_sound.setVolume(-myPoint.y);

updateAfterEvent();

}

Groove movie clip is 100 pixels tall

Hence its local coordinates range from -100 to 0

To change this range to positive value negative sign(-) is used

The result is a range from 100 at tope and 0 at bottom

That can be used as the setVolume parameter

Dynamic sound control 05dynamicsound.fla


Dynamic sound control 05dynamicsound fla9

Create sound object and play button

myMusic_sound= new Sound();

myMusic_sound.attachSound("music");

startButton_btn.onRelease = function() {

myMusic_sound.start(0, 10);

}

Test the movie

When you drag the slider up and down it dynamically changes the volume

Dynamic sound control 05dynamicsound.fla


External sounds 06externalsound fla

Internal sounds (from the library) increase the .swf file size

loadSound () allows playing external sounds that can be kept outside flash movie

Allows change the sound file easily

Smaller flash file size

mySound = new Sound();

mySound.loadSound("kennedy.mp3", true);

loadSound("kennedy.mp3", true);

Kennedy.mp3name of the external sound file

Truestreaming (true) or event (false) sound

External sounds 06externalsound.fla


External sounds 06externalsound fla1

Streaming sounds start play as soon as enough data downloads

one stream per sound object

long passages of music

narration

Event sounds must be downloaded completely before they can play

require start() command to plav

short sounds

sound effects

External sounds 06externalsound.fla


Sound properties 07soundproperty fla

mySound = new Sound();

mySound.loadSound("kennedy.mp3", true);

_root.onEnterFrame = function()

{

image_mc._alpha = (mySound.position / mySound.duration) * 100;

image_mc._xscale = 50 + ((mySound.position / mySound.duration) * 50);

image_mc._yscale = 50 + ((mySound.position / mySound.duration) * 50);

}

Positionmeasures the numbers of milliseconds a sound has been playing

Durationtotal number of milliseconds in the sound

Sound properties 07soundproperty.fla


Sound properties 07soundproperty fla1

Modifies the image according to the sound length

As the sound plays, the image slowly reveals itself

When the sound ends the image is completely revealed

_root.onEnterFrame = function()

{

image_mc._alpha = (mySound.position / mySound.duration) * 100;

image_mc._xscale = 50 + ((mySound.position / mySound.duration) * 50);

image_mc._yscale = 50 + ((mySound.position / mySound.duration) * 50);

}

(Position / duration) * 100 gives the percentage of sound that has downloaded

Increases the alpha of the movie clip as the sound plays so that the movie clip begins transparent and ends opaque

Sound properties 07soundproperty.fla


Detect sound event 07soundproperty fla

onSoundComplete()detects the end of the sound

mySound.onSoundComplete = function()

{

image_mc.attachMovie("end", "ending_mc", 1);

}

When sound ends a movie clip “end” is attached to the image_mc movie clip. The registration point of the attached movie clip was modified in advance so that it appears in correct position.

Detect sound event 07soundproperty.fla


  • Login