SourceTec Software

It is currently Wed Apr 23, 2014 5:22 pm

All times are UTC + 8 hours




Post new topic Reply to topic  [ 2 posts ] 
Author Message
PostPosted: Fri Mar 07, 2008 7:04 pm 
Offline
Guru

Joined: Thu Jul 08, 2004 2:19 pm
Posts: 943
It seems few of you guys yet to understand how sound works in flash.

I have already written something here http://www.sothink.com/phpBB2/viewtopic.php?t=28316 about Sound in SWF QUICKER (or in flash) but it seem some of you do not realy search the forum but even thought I have said that, this time I have made Pausing and Resuming a Sound tutorial and hope it will be useful for users here.


Tutorial : for Pausing and Resuming a Sound

Discussion accroding in one of my flash books

The Sound class does not provide built-in methods to pause and resume a sound. However, with a little bit of code, you can achieve the same result. The key is to store the sound's position property before stopping (pausing) the sound and then use that value to tell Flash at what point to resume playback.


Therefore, to pause a sound:

Get the value of the sound's position property and store it in a variable:

pauseTime = mySound_sound.position;
Call the stop( ) method:

mySound_sound.stop( );
And when you want to resume the sound, simply do the following:

Convert the stored position, in milliseconds, into a starting offset, in seconds, by dividing by 1000.

Call the start( ) method and pass it the appropriate value for the offset:

mySound_sound.start(pauseTime/1000);

And I come up with following code and it works great .




// This code has been used in the demo
// this code will load the external audio
mySound = new Sound();
mySound.loadSound("your Audio file.mp3", false);
mySound.start(true);

//code for pause button to stop a sound
pauseButton.onRelease = function ()
{
mySound.stop();
// this code will disable stop button when clicked once
playButton.enabled = true;
pauseButton.enabled = false;
};

//code for play button to resume a sound
playButton.onRelease = function ()
{
mySound.start(mySound.position/1000);
// this code will disable play button when clicked once and then enbles the stop button
playButton.enabled = false;
pauseButton.enabled = true;
};


Top
 Profile  
 
PostPosted: Wed Feb 09, 2011 12:24 am 
Offline
Member

Joined: Sun Jan 23, 2011 12:14 am
Posts: 2
Hi,

I use thr following code to play sound on button click in Swf Easy 6.0, but it doesn't work,
What is wrong with the code?

mySound = new Sound();
mySound.loadSound("click.mp3", false);
mySound.start(true);

I placed click.mp3 in the same folder as .gla file, and also added file to scene.
There is no sound playing when I click the button.
Any idea what is wrong?


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC + 8 hours


Who is online

Users browsing this forum: No registered users and 8 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
Powered by phpBB® Forum Software © phpBB Group