View comments | RSS feed

Sound.start()

Availability

Flash Player 5.

Usage

my_sound.start([secondOffset:Number, loop:Number]) : Void

Parameters

secondOffset An optional parameter that lets you start playing the sound at a specific point. For example, if you have a 30-second sound and want the sound to start playing in the middle, specify 15 for the secondOffset parameter. The sound is not delayed 15 seconds, but rather starts playing at the 15-second mark.

loop An optional parameter that lets you specify the number of times the sound should play consecutively.

Returns

Nothing.

Description

Method; starts playing the last attached sound from the beginning if no parameter is specified, or starting at the point in the sound specified by the secondOffset parameter.

Example

The following example creates a new Sound object, and loads a sound. Loading the sound is handled by the onLoad handler, which allows you to start the song after it's successfully loaded. Then the sound starts playing using the start() method. Create a new FLA file, and add the following ActionScript to your FLA or AS file. For this example to work, you must have an MP3 called song1.mp3 in the same directory as your FLA or AS file.

this.createTextField("status_txt", this.getNextHighestDepth(), 0,0,100,22);

// create a new Sound object
var my_sound:Sound = new Sound();
// if the sound loads, play it; if not, trace failure loading
my_sound.onLoad = function(success:Boolean) {
   if (success) {
      my_sound.start();
      status_txt.text = "Sound loaded";
   } else {
      status_txt.text = "Sound failed";
   }
};
// load the sound
my_sound.loadSound("song1.mp3", true);

See also

Sound.stop()

Comments


JaXtus said on Nov 8, 2004 at 6:17 PM :
I thought that a sound object set to true(streeming) would begin playing after the 5 second default _soundbuftime. wtf
maaikeeee said on Dec 10, 2004 at 9:07 AM :
update
maaikeeee said on Dec 10, 2004 at 9:07 AM :
mp3
blueghozt said on Jan 19, 2005 at 3:41 AM :
I have a dynamically called MP3 sound loaded as streaming and it plays fine but just once, I programmed a button to restart the sound and loop it continuously with:

on(release){
_root.my_sound.start(0,1000);
}

however this only plays it once also - does the loop argument work with streamed sounds?
Francis Cheng said on Jan 21, 2005 at 12:11 AM :
Hi blueghozt,

No, the loop argument does not work with streaming sounds. I'll add a note to the documentation to that effect. Apologies for any inconvenience this has caused you.
frankhdz said on Feb 21, 2005 at 10:35 AM :
I created the sound as an event and it does not what to play for me at all

var mySound:Sound = new Sound();
mySound.loadSound("sound/nrc.mp3", false);


trace(BL = mySound.getBytesLoaded());
trace(NL = Math.round(BL / mySound.getBytesTotal() * 100));
if (NL >= 100) {
trace("File Loaded");
trace(mySound.start(50,999));
//stop();
} else {
mySound.stop();
trace("File Not Loaded");
play();
}
Gratman said on Feb 21, 2005 at 3:36 PM :
it will only hit your 'if' once and if it is not loaded then too bad.

use the onLoad function like they say to:

my_sound.onLoad = function(success:Boolean) {
if (success) {
this.start();
}
}

by the way the code in the example won't work in AS2 files. it should read as above with 'this' instead of 'my_sound'.
sixthneo said on Mar 22, 2005 at 10:47 PM :
Quick question: Suppose i m playing 2 sounds and i want to reduce the volume for one and increase for other is it possbile.
Churowa said on Apr 23, 2005 at 10:05 AM :
Quick implementation question: In the Sound.start() function, why did you make the offset in seconds, when the Sound.position and Sound.duration values are returned in milliseconds? Wouldn't it be simpler to stick to one, either seconds or milliseconds?
swartz1999 said on Apr 28, 2005 at 11:42 AM :
Thanks for taking the time to post on Livedocs. LiveDocs comments are for documentation comments and they are reviewed by Technical Writers only. I encourage you to submit a feature request using our feature request page:
http://www.macromedia.com/support/email/wishform/

Or you may want to post your comment to the online forums:
http://webforums.macromedia.com/flash
CarlosQuesada said on Jun 1, 2005 at 6:59 AM :
You could loop a streaming sound by using the following code:

var my_sound = new Sound();
my_sound.onLoad = function() {
if (success) {
this.start();
}
};
my_sound.onSoundComplete = function() {
this.start();
};
my_sound.loadSound("my_song.mp3", true);
kamcknight said on Jun 15, 2005 at 4:23 PM :
I am trying to load and play an mp3 file. I have code that works for another flash movie I wrote and it works fine for the other movie. But in this movie it doesn't seem to work. Here is my code:

playSound = function(songToPlay:String)
{
stopAllSounds();
var song:Sound = new Sound();
song.loadSound("music/" + band + "/" + album + "/" + songToPlay + ".mp3", true);

song.onLoad = function(success)
{
if(success)
{
song.start();
}
}

This is to be executed when a button is clicked. The song will play if i click the button twice, but not on the first click.
kamcknight said on Jun 15, 2005 at 4:27 PM :
I actually found the problem though I don't understand why. My onLoad function had to be declared outside of the other function and song needed to be a global variable. Can anyone tell me why? Or if there IS a way to do it the first way?

 

RSS feed | Send me an e-mail when comments are added to this page | Comment Report

Current page: http://livedocs.adobe.com/flash/mx2004/main_7_2/00001688.html