5

Blog Entry #25

posted in Solving

AS2 setVolume to zero turn off video volume

Why my Video volume turns off when I run mySound.setVolume(0) ?
To understand this, compare AS2 and AS3
In AS3, to play a sound file, you need to create a Sound object, that is played through a SoundChannel object.

  1.  
  2. var mySound : Sound = new Sound();
  3. var myChannel : SoundChannel;
  4. //load a sound file
  5. mySound.load(new URLRequest("soundfile.mp3"));
  6. //then play it through the SoundChannel
  7. myChannel = mySound.play();
  8.  

To play and control separately two differents soundfiles playing simultaneously, you need two differents SoundChannel.

And in AS3, video component has its own SoundChannel.
In AS2, there is no SoundChannel, but it is almost the same way. Each MovieClip or Containeur, has its own depth, and you can't display two of them in the same depth. With Sound object it almost the same, you can play two differents soundfiles in a depth, but you can't control them separately because they are using the same Channel(depth).

If your are facing this trouble you might have something similar to this code :

  1.  
  2. //In the same container (MovieClip or Stage)
  3. var myVideo:Video;
  4. var mySound:Sound = new Sound(this);
  5. //... mySound.loadSound(...), blablabla
  6. //And
  7. mySound.setVolume(0);
  8. //wich also turns of myVideo sound
  9.  

So the video component and the sound object has the same parent(container). To skip this trouble, just create a container for the sound object.

  1.  
  2. var myVideo:Video;
  3. var soundContainer:MovieClip = this.createEmptyMovieClip("mySoundContainer" , this.getNextHighestDepth());
  4. var mySound:Sound = new Sound(soundContainer);
  5.  

And the problem is solved.

0 comments about this entry

Write a comment

edit




Insert :


Search Engine

Search blog entries


Search

Recommended Feed

keep your mind opened ...