A Flash Developer Resource Site














Internet Commerce

Partners & Affiliates














Developer Channel

internet.com


Featured Flash FLA
Gallery Downloads 11337 Flash Movies | 1 New Flash Movies Added
What's New | Top 100

Featured FLA

» Author: Bugra Ozden
» Title: Skatalog v9 - product catalog
» Description: Create your product catalog easly and publish on your website or Create your image gallery, documents list, portfolio. Fully XML Driven
» More by Bugra Ozden


Random FLAs | Add Flash Movie
Featured Flash Site
Gallery Downloads 5828 Flash Sites | 0 New Flash Links
What's New | Top 100 Flash Site

Featured Site

» Posted in the Flash Kit Links section
» Title: Creative DW Image Show PRO
» Description: Creative DW Image Show PRO is a Dreamweaver extension which enables the user to create multimedia presentations. It combines the features of the popular Creative DW Image Show with the ability to add professional text effects to slides (similar to After Effects). The product is very customizable: the user can choose the duration of the transition effects, the slide motion start and end position, zoom and panning type for both images and texts.


Random Links | Add your own Flash Related Links
Flash Tutorials 1280 Tutorials 7 New Tutorials Added!
What's New | Top100

» Make a Flash Slide Show Screen Saver
» Simple flash making tutorial for thanksgiving
» Create flash banner for website
» Create xml slideshow with free template
» How to Insert a Multilingual Subtitle Into Your Flash Video Studio
» How to Create Cool Halloween Slideshow
» Debugging flash using the Firebug console
» Create Flash Slideshow on Blogger
» FLASH TRICKS IN WEB ADVERTISING: FLASH BANNERS
» Unknown Tag: Title10
Random Tutorial | Add Site

Sr Instructional Designer D2L-Moodle,Clearance
WSI Nationwide, Inc.
US-NJ-Fort Monmouth

Justtechjobs.com Post A Job | Post A Resume


Tutorials Home What's New Top Rated Submit myTutes Random!

Search Tutorials


Tutorials Tutorials » Audio

Categories Flash MX Sound Object Tutorial
Author: Kenny Bellew

 
Page 12
«prev ... 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 ... next»

How to Control the Position of a Sound Object


Flash MX allows much greater control over the time position of a sound object. Because you can detect when an exact amount of seconds have passed from the beginning of a sound, it is possible to use a sounds position in time to activate events in your Flash movie. This provides an additional powerful tool to control your presentation.

Fading a Sound Object Five Seconds from the End of the Song

Fig. 10: Example of fading a sound object five seconds from the end of the song

To begin a fade out five seconds from the end of a song, the sound object properties "duration" and "position" can be used. The property "duration" reports the duration of a sound in milliseconds. The property "position" reports the number of milliseconds the sound has been playing.

For a sound object defined with the instance name of "myMusic", the syntax for these methods is as follows:

myMusic.duration;
 myMusic.position;

Using the "duration" property, you can define a variable that equals the duration of a sound minus 5 seconds:

myMusicDuration = _root.myMusic.duration/1000;
myMusicPosition = _root.myMusic.position/1000;
fadeEnd=(songDuration-5);

In the above example, the variable "myMusicDuration" is defined as equaling the duration of the sound object "myMusic" divided by 1000. The variable is divided by 1000 because the duration is reported in milliseconds (5000 milliseconds equals 5 seconds). Similarly, the variable "myMusicPosition" is defined as equaling the current position of the sound object "myMusic". Finally, the variable "fadeEnd" is defined as "myMusicDuration" minus five. The number five can be used (versus 5000) because "myMusicDuration" has already been divided by 1000.

By placing the above three lines of code in a movie clip that loops (adding it to the first frame) using the event handler, "onEnterFrame", the variables are updated every time the frame is processed. The ActionScript watches for "fadeEnd" to be equal to or less than "songPosition", and then begin fading the volume of the sound object.

this.onEnterFrame = function () {
myMusicDuration = _root.myMusic.duration / 1000;
myMusicPosition = _root.myMusic.position / 1000;
fadeEnd = (myMusicDuration - 5);
//
//Fade Out
//
if (fadeEnd <= songPosition && myMusicVolume>0 && playing==true) {
if (myMusicVolume<=1) {myMusicVolume=0}
_root.myMusic.setVolume(myMusicVolume);
myMusicVolume=myMusicVolume-1;
}
}

In order to make this work, the variable "myMusicVolume" must equal some number before the above script runs. If it does not, the first time you indicate that the setVolume is "myMusicVolume", the volume will be zero. There are a few ways to resolve this. One way is to define "myMusicVolume" as a variable at the same time as the sound object is defined.

myMusic = new Sound(myMusicMc);
myMusic.attachSound("myMusic01");
myMusicVolume=100;
myMusic.setVolume(myMusicVolume);


Experiment with the Flash example in Fig. 10 to see the sound fade in or out.

«prev ... 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 ... next»

» Level Intermediate

Added: : 2002-08-13
Rating: 9.12 Votes: 657
Hits: 3000
» Author
Kenny Bellew is a technical writer in Minneapolis, MN. He's currently interested in becoming involved in other writing-related Flash projects.
» Download
Download the files used in this tutorial.
Download (6170 kb)
Get conversion and unzipping tools for PC and Mac here!

» Forums
More help? Search our boards for quick answers!

Please rate this tutorial, 10 is the top rating, you can also click the comments link to read/write a review.
10 9 8 7 6 5 4 3 2 1
Read or Post Comments
 
   
 

internet.commediabistro.comJusttechjobs.comGraphics.com

Search:

WebMediaBrands Corporate Info

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | Shopping | E-mail Offers | Freelance Jobs