View Full Version : action after sound stops
Ok, step 2. And I have looked around with no luck.
Loading sound dynamically in .AS file exclusivally...
var my_sound:Sound = new Sound();
my_sound.attachSound("interweb.wav");
my_sound.start();
//next actions
I want the sound to finish before the next action.
Tried .stop() at various places, no luck.
Suggestions?
Thanks.
amen0
09-27-2005, 10:52 PM
you can use the onSoundComplete event,
var my_sound:Sound = new Sound();
my_sound.attachSound("interweb.wav");
my_sound.start();
my_sound.onSoundComplete=function(){
//next Action
}
deadbeat
09-27-2005, 10:59 PM
Use onSoundComplete:
function callback(){
// put next actions here
}
var my_sound:Sound = new Sound();
my_sound.attachSound("mySoundID");
my_sound.onSoundComplete = callback;
my_sound.start();
LOL - beaten to it...
K.
Sorry, not seeing it or working yet...
Oh, .Net is so much straight foward :D
Ok, this is what is going on.......
//constructor
btnYes = _root.attachMovie("btnYes_mc", "yes", _root.getNextHighestDepth(), {_x:400.0, _y:130.0});
btnYes.onRelease = Delegate.create(this, sendScore);
//this button is not visible until another is
//pressed but does call it's function sendScore
//end constructor
public function sendScore(){
var my_sound:Sound = new Sound();
my_sound.attachSound("interweb.wav");
my_sound.start();
//does not work below
my_sound.onSoundComplete=function(){
callbackSendScore();
}
//does not work below
//my_sound.onSoundComplete = callbackSendScore;
//my_sound.stop();
//trace works
trace('calledself');
}
public function callbackSendScore(){
trace('callbackSendScore'); //never called on both attempts
}
Just can't get the callback called but plays sound.....
oldnewbie
09-28-2005, 01:26 AM
This works fine for me in MX only...
function callback(){
trace("Sound has played!");
// put next actions here
}
my_sound = new Sound();
my_sound.attachSound("911");
my_sound.onSoundComplete = callback;
my_sound.start();
amen0
09-28-2005, 02:56 AM
//constructor
btnYes = _root.attachMovie("btnYes_mc", "yes", _root.getNextHighestDepth(), {_x:400.0, _y:130.0});
btnYes.onRelease = Delegate.create(this, sendScore);
//this button is not visible until another is
//pressed but does call it's function sendScore
//end constructor
public function sendScore(){
var my_sound:Sound = new Sound();
my_sound.attachSound("interweb.wav");
my_sound.start();
my_sound.parent=this;
my_sound.onSoundComplete=function(){
my_sound.parent.callbackSendScore();
//will work :) hope so
}
trace('calledself');
}
public function callbackSendScore(){
trace('callbackSendScore');
}
Sorry, that didn't work either due to the error:
There is no property with the name 'parent'.
my_sound.parent=this;
Am I missing an import?
How does it know when the sound is finished playing?
Should the sound file duration be declared?
Also remember, I am using a .AS file exclusively!
None of this code is on the stage.
Thanks,
Does anyone have an explanation why the onSoundComplete won't work?
I have been trying everything with no luck.
The .wav file (and have tried mp3) is in the libray and the linkage is set.
I am using this in a .as file.
Thanks,
deadbeat
09-28-2005, 06:32 PM
Since you're using it in a class, the my_sound object doesn't have access to the class methods, so it can't find the callback function...
Try using Delegate to redirect the function call to the class object:
var my_sound:Sound = new Sound();
my_sound.attachSound("interweb.wav");
my_sound.start();
my_sound.onSoundComplete=Delegate.create(this,call backSendScore);
HTH,
K.
Makes sense it can't access the class for the onSoundComplete but your suggestion didn't work.
It instantly started playing the sound as soon as the swf started.
[Edit] - sorry, forgot I tried putting sound onstage, that's why it played instantly.
The sound still worked on the button release, but did not access the onSoundComplete.
Even tried unchecking the box in the linkage for importing to first frame with no luck.
Any more suggestions?
Update:
Seems most of the suggestions do work.
But, whether it was callback or callbackSendScore, it needed to be callbackSendScore() - note the ()
It is calling callbackSendScore but, instantly. There is no delay waiting for the sound to complete.
|
vBulletin® v3.8.5, Copyright ©2000-2012, Jelsoft Enterprises Ltd.