Groups | Blog | Home
all groups > flash actionscript > july 2007 >

flash actionscript : onsoundcomplete; onload



nik c
7/6/2007 6:35:40 PM
Hi,

Maybe I am just having a mental block and can't see the wood for the trees.
The issue is that I am creating a sound object inside a function, and start a
sound playing. Then as long as I address the sound object from inside other
functions it works fine, but not if I address it outside of one.

Here is the code:
[Q]
var currentSound=this.createEmptyMovieClip("mySoundShell",100000);
var mySound;
var moveScrubberInt:Number; // for a interval I am setting later

function playAudio():Void {
mySound = new Sound(currentSound);
mySound.loadSound(contentArr[currentUnit][1][2], true);
mySound.start()
// get scrubber moving
moveScrubberInt = setInterval(moveScrubber, 100);
}
mySound.onLoad = function(success:Boolean) { // the code in here does not get
called at all
trace("on load"); /
var totalSeconds:Number = this.duration/1000;
var minutes:Number = Math.floor(totalSeconds/60);
var seconds = Math.floor(totalSeconds)%60;
if (seconds<10) {
seconds = "0"+seconds;
}
duration_txt.text = minutes+":"+seconds
}
mySound.onSoundComplete = function() { // the code in here does not get called
at all
clearInterval(moveScrubberInt);
trace("CLEARED - moveScrubberInt: " + moveScrubberInt);
mySound.loadSound();
playPause_mc.gotoAndStop("play");
timelineScrubber_mc.scrub_mc._x = 0;
//trace(s.position + ", " + s.duration);
trace("WHERE AM I, onSoundComplete: " + this);
}
[/Q]

but this code works fine:
[Q]
//Pauses audio
var pos;
function pauseIt():Void
{
pos = mySound.position;
trace("^^^^^^^^^^^^^^^pauseIt^^^^^^^ pos: " + pos);
mySound.stop();
clearInterval(moveScrubberInt);
}
[/Q]

Where is my block? Or what is going on here?

I would be grateful for any hints?

Thanks,
Nik
kglad
7/6/2007 7:02:51 PM
use:



var currentSound = this.createEmptyMovieClip("mySoundShell", 100000);
var mySound:Sound = new Sound(currentSound);
var moveScrubberInt:Number;// for a interval I am setting later

function playAudio():Void {
mySound.loadSound("music1.mp3",true);
// get scrubber moving
moveScrubberInt = setInterval(moveScrubber, 100);
}
mySound.onLoad = function(success:Boolean) {// the code in here does not get
called at all
//mySound.start(); // you don't need to start a streaming sound. but if
your sound were not streaming, start() here.
trace("on load");
var totalSeconds:Number = this.duration/1000;
var minutes:Number = Math.floor(totalSeconds/60);
var seconds = Math.floor(totalSeconds)%60;
if (seconds<10) {
seconds = "0"+seconds;
}
duration_txt.text = minutes+":"+seconds;
};
mySound.onSoundComplete = function() {// the code in here does not get called
at all
clearInterval(moveScrubberInt);
mySound.loadSound();
timelineScrubber_mc.scrub_mc._x = 0;
};
nik c
7/6/2007 7:22:53 PM
Hi,

Thanks! Initialising the sound object outside the function makes the onlaod
adn onsoundcomplete work, but spoils the .position resetting for my timeline
scrubber display (this is ment to show the posiiton of the playhead in the
audio file so the user knows how much of the soundfile has been played already.

It seems I can have either one or the other!

Is there a solution!

Nik
kglad
7/6/2007 8:39:27 PM
nik c
7/6/2007 10:14:06 PM
I think you got it this time!

It took a while to realise that now that I am not streaming, I need to
'manually' start the playback in the oncomplete handler, but it is in fact
working now!

Magnificent! You're the (wo/man!

Nik
kglad
7/6/2007 10:15:44 PM
AddThis Social Bookmark Button