Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Adding back the sound

Community Beginner ,
Jan 14, 2015 Jan 14, 2015

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!

TOPICS
ActionScript
247
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 14, 2015 Jan 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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jan 14, 2015 Jan 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?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 14, 2015 Jan 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);

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jan 14, 2015 Jan 14, 2015

Yes, but when the animation is done using a tween.

It has only one frame. Or?

I used tween, as it takes less memory compared to enterFrame.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 14, 2015 Jan 14, 2015
LATEST

then use a tween update listener.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines