. .
CREATE OR DIE Special Downloads Shop webinale

Schauplatz

CodeSnippets

Sound.fadeIn und fadeOut - Audio ein- und ausblenden

  • Currently 5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Verwendung

In Flash können nicht nur MovieClip-instanzen ein- und ausgeblendet werden, sondern auch die Audiowiedergabe. Die folgenden prototypes-Methoden ermöglichen es Ihnen, einen Sound ein- bzw. auszublenden. der Parameter pUpdateZeit legt hierbei das Zeitintervall für den Ein- / Ausblendevorgang fest.

Code - Flash MX bis Flash 8
  1. Sound.prototype.fadeIn = function (pUpdateZeit:Number):Void
  2. {
  3. this.sound_obj != undefined ? (clearInterval (this.sound_obj), delete this.sound_obj) : null;
  4. this.sound_obj = setInterval (function ()
  5. {
  6. var volume = arguments[0].getVolume ();
  7. volume < 100 ? arguments[0].setVolume (volume + 1) : (clearInterval (arguments[0].sound_obj), delete arguments[0].sound_obj);
  8. }, pUpdateZeit, this);
  9. };
  10. Sound.prototype.fadeOut = function (pUpdateZeit:Number):Void
  11. {
  12. this.sound_obj != undefined ? (clearInterval (this.sound_obj), delete this.sound_obj) : null;
  13. this.sound_obj = setInterval (function ()
  14. {
  15. var volume = arguments[0].getVolume ();
  16. volume > 0 ? arguments[0].setVolume (volume - 1) : (clearInterval (arguments[0].sound_obj), delete arguments[0].sound_obj);
  17. }, pUpdateZeit, this);
  18. };
  19. ASSetPropFlags (Sound.prototype, ["fadeIn", "fadeOut"], 1);
Anwendung
  1. audio = new Sound ();
  2. audio.attachSound ("musik");
  3. audio.start (0, 100);
  4. audio.setVolume (0);
  5. // FadeIn
  6. audio.fadeIn (35);
  7. // FadeOut
  8. audio.setVolume(100);
  9. audio.fadeOut(45);

Caroline und Matthias Kannengiesser

Tags
    keine Tags
Kommentare
Bisher keine Kommentare