Skip to main content
Known Participant
January 14, 2015
Question

Adding back the sound

  • January 14, 2015
  • 5 replies
  • 303 views

Hi,

I need some advice.

I have a tween, which is rotating the (MovieClip01) and playing a sound on the same time.

The sound is a song, 7.2 seconds long.

rotationTween = new Tween(this, "rotation", None.easeIn, 0, 2880, 7.5, true);

When another animation starts (MovieClip02), also with sound, the sound for MovieClip01 is stopped. In order not to have mix and also to save some memory, as the second animation is quite big.

In case the second animation is stopped (animation and sound), but the first one still lasting, I would like the sound of the first MovieClip01 to start playing again. But not from beginning, but from the place where the Tween is at that point of time.

I could just mute the sound for the first animation and then unmute, but that wouldn't free up the memory.

And so my question - how to find the current position of the tween to use it for calculating the place from where the sound should start playing again?

I thought to stop the rotation tween at that moment, take the rotation value and use it for calculating the starting position for the sound.

But the rotation value seems to be between -180 and 180.

rotationTween.stop();

curRotation = this.rotation;

trace("curRotation is " + this.rotation);

Many thanks in advance!

This topic is closed to new replies. Start a new post to keep the conversation going.

5 replies

kglad
Community Expert
Community Expert
January 14, 2015

store your soundchannel's position in a variable when you're stopping it and use that variable in your sound's play method to restart at the correct offset.

rahexAuthor
Known Participant
January 14, 2015

but wouldn't that start the sound from the place it was stopped?

The animation of the MovieClip01 has been playing in meanwhile.

So the audio should skip a part of the track and not start from where it was stop, but a bit later.

How to find that spot?

kglad
Community Expert
Community Expert
January 14, 2015

yes, that would start it where it was stopped.  if the movieclip is continuing to play you can use an approximation to find the offset:

var ms:int = int(1000*(yourmovieclip.currentFrame-yourmovieclip_startframe)/stage.frameRate);