Zurück   Flashforum > Flash > ActionScript > ActionScript 1

Antwort
 
LinkBack Themen-Optionen Ansicht
Alt 10-08-2005, 17:44   #1 (permalink)
Neuer User
 
Registriert seit: Feb 2004
Beiträge: 78
Sounds nach unbestimmter Zeit zufällig abspielen

Hi Leute!
Also ich habe eine ganze Reihe an Sounds, die für ein bisschen Atmo in meinem Flash Film sorgen sollen. Jetzt möchte ich, dass nach irgendeiner Zeit, z.B. 5 sec
Sound x abgespielt wird, danach wieder nach x sec ein anderer Sound oder von mir aus auch der gleiche wie vorher.

Die Sounds sollen also zufällig und nach einer zufälligen Zeit abgespielt werden.
Ist sowas irgendwie möglich?

Gruß,
Kempi
Kempi ist offline   Mit Zitat antworten
Alt 10-08-2005, 17:48   #2 (permalink)
Farbe ist Luxus
 
Benutzerbild von ludabruda
 
Registriert seit: May 2003
Ort: Köln
Beiträge: 2.405
Hi,

ja, schau dir dazu mal setinterval(), clearInterval() und random() an.

Mit setInterval wird immernach einer bestimmten Zeit eine Funktion aufgerufen.
Mit clearInterval wird dieses intervall wieder beendet.

Mittels random() erzeugst du zufällig eine Zahl. Wenn du deine Sounds also durchnumerierst, musst du nur mit dieser Zahl den entsprechenden Soudn abspielen.

Grüße
Sascha
__________________
12:15, press return
ludabruda ist offline   Mit Zitat antworten
Alt 11-08-2005, 08:53   #3 (permalink)
Neuer User
 
Registriert seit: Feb 2004
Beiträge: 78
Ja, OK! Mit dem random() bekomme ich ja noch irgendwie hin!
Aber kann mir das mit den Intervallen mal bitte einer etwas genauer erklären?
Wie funzt das?
Kempi ist offline   Mit Zitat antworten
Alt 11-08-2005, 09:26   #4 (permalink)
Farbe ist Luxus
 
Benutzerbild von ludabruda
 
Registriert seit: May 2003
Ort: Köln
Beiträge: 2.405
Du hast eine beliebige Funktion erstellt, sagen wir:

function abc () {
trace("abc");
}

Diese soll alle 5 Sekunden aufgerufen werden:

this.intervallID = setInterval("abc",5000);

Mit clearInterval(this.intervallID) kannst du das Intervall stoppen, sonst
läuft es ewig. Also einfach das Intervall stoppen und mit neuer Zufallszeit wieder starten.

Grüße
Sascha
__________________
12:15, press return
ludabruda ist offline   Mit Zitat antworten
Alt 12-08-2005, 16:46   #5 (permalink)
Neuer User
 
Registriert seit: Feb 2004
Beiträge: 78
Habs mal so probiert, dass klappt aber noch nicht.
ActionScript:
  1. var ambisound = Math.ceil(Math.random()* 7);
  2. var timeMath.ceil(Math.random()* 5000);
  3.  
  4. this.intervalID = setInterval("SoundAmbiente", time);
  5. clearInterval(this.intervalID);
  6.  
  7. function SoundAmbiente(ambisound) {
  8.     if (ambisound == 1) {
  9.         soundAmbiente = new Sound();
  10.         soundAmbiente.loadSound("sounds/1.mp3" , true);
  11.         soundAmbiente.start();
  12.     }
  13.     else if (ambisound == 2) {
  14.         soundAmbiente = new Sound();
  15.         soundAmbiente.loadSound("sounds/2.mp3" , true);
  16.         soundAmbiente.start();
  17.     }
  18.     else if (ambisound == 3) {
  19.         soundAmbiente = new Sound();
  20.         soundAmbiente.loadSound("sounds/3.mp3" , true);
  21.         soundAmbiente.start();
  22.     }
  23.     else if (ambisound == 4) {
  24.         soundAmbiente = new Sound();
  25.         soundAmbiente.loadSound("sounds/4.mp3" , true);
  26.         soundAmbiente.start();
  27.     }
  28.     else if (ambisound == 5) {
  29.         soundAmbiente = new Sound();
  30.         soundAmbiente.loadSound("sounds/5.mp3" , true);
  31.         soundAmbiente.start();
  32.     }
  33.     else if (ambisound == 6) {
  34.         soundAmbiente = new Sound();
  35.         soundAmbiente.loadSound("sounds/6.mp3" , true);
  36.         soundAmbiente.start();
  37.     }
  38.     else if (ambisound == 7) {
  39.         soundAmbiente = new Sound();
  40.         soundAmbiente.loadSound("sounds/7.mp3" , true);
  41.         soundAmbiente.start();
  42.     }
  43. }
Falscher Aufruf oder so? Sorry, aber komme mit diesen Interval Sachen einfach nicht zurecht.
Kempi ist offline   Mit Zitat antworten
Alt 12-08-2005, 17:14   #6 (permalink)
................
 
Benutzerbild von Der Frager
 
Registriert seit: Jun 2004
Beiträge: 15.890
Büschen lang die Geschichte:
ActionScript:
  1. function Intervall() {
  2.     clearInterval(intervalID);
  3.     intervalID = setInterval(SoundAmbiente, Math.ceil(Math.random()*5000));
  4. }
  5. function SoundAmbiente() {
  6.     var ambisound = random(7)+1;
  7.     soundAmbiente = new Sound(this);
  8.     soundAmbiente.loadSound("sounds/"+ambisound+".mp3", true);
  9.     soundAmbiente.start();
  10.     Intervall();
  11. }
  12. Intervall();
__________________

ternärer Konditionaloperator

+++ Bitte keine Privat-Nachrichten bezüglich Flashfragen! +++
Der Frager ist offline   Mit Zitat antworten
Alt 13-08-2005, 17:32   #7 (permalink)
Neuer User
 
Registriert seit: Feb 2004
Beiträge: 78
Danke schön Leute! Klappt!
Kempi ist offline   Mit Zitat antworten
Alt 10-09-2005, 22:28   #8 (permalink)
Neuer User
 
Benutzerbild von berliner
 
Registriert seit: Jan 2002
Ort: Berlin
Beiträge: 298
hi,
ich frag mal nach hab das auch probiert bei mir geht net,
so siehts aus
ActionScript:
  1. mySound1 = new Sound(mc1);
  2. mySound1.attachSound("loop");
  3. mySound1.start(0, 9999);
  4. mySound1.setVolume(20);
  5. function Intervall() {
  6.     clearInterval(intervalID);
  7.     intervalID = setInterval(SoundAmbiente, Math.ceil(Math.random()*5000));
  8. }
  9. function SoundAmbiente() {
  10.     var ambisound = random(4)+1;
  11.     trace(ambisound);
  12.     soundAmbiente = new Sound(this);
  13.     soundAmbiente.loadSound("sounds/sampel"+ambisound+".mp3", true);
  14.     soundAmbiente.start(0, 1);
  15.     soundAmbiente.setVolume(20);
  16.     Intervall();
  17. }
  18. Intervall();
Die 4 Sampels sollen jetzt per Zufall auf den loop geschossen werden
das macht der 1mal und das wars...
ich weiss das liegt am clearInterval(intervalID) aber wie umgeh ich das
und wie bekomm ich den ganzen Sound ausgeschaltet?
ohne das der interval weiterläuft...
Danke für Eure hilfe
g.
berliner ist offline   Mit Zitat antworten
Antwort

Lesezeichen

Themen-Optionen
Ansicht

Forumregeln
Es ist Ihnen nicht erlaubt, neue Themen zu verfassen.
Es ist Ihnen nicht erlaubt, auf Beiträge zu antworten.
Es ist Ihnen nicht erlaubt, Anhänge hochzuladen.
Es ist Ihnen nicht erlaubt, Ihre Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks sind an
Pingbacks sind an
Refbacks sind an



Alle Zeitangaben in WEZ +1. Es ist jetzt 07:20 Uhr.

Domains, Webhosting & Vserver von Host Europe
Unterstützt das Flashforum!
Adobe User Group


Copyright ©1999 – 2012 Marc Thiele