Zurück   Flashforum > Flash > ActionScript > ActionScript 1

Antwort
 
LinkBack Themen-Optionen Ansicht
Alt 13-08-2005, 17:22   #1 (permalink)
Neuer User
 
Registriert seit: Aug 2005
Beiträge: 23
sound fertig, dann nächstes bild

hi
ich hab ein problem ich weiß nich wie ich es machen soll das wenn ein sound fertig abgespielt ist das nächste bild in der zeitleiste kommt... geht das überhaupt?
danke schonma

greetz denjo
Denjo132 ist offline   Mit Zitat antworten
Alt 13-08-2005, 17:30   #2 (permalink)
:Void
 
Benutzerbild von janoshnosh
 
Registriert seit: Jun 2005
Ort: börlin
Beiträge: 931
Sound.onSoundComplete
Availability
Flash Player 6.

Usage
my_sound.onSoundComplete = function(){
// your statements here
}

Parameters
None.

Returns
Nothing.

Description
Event handler; invoked automatically when a sound finishes playing. You can use this handler to trigger events in a SWF file when a sound finishes playing.

You must create a function that executes when this handler is invoked. You can use either an anonymous function or a named function.

Example
Usage 1: The following example uses an anonymous function:
ActionScript:
  1. var my_sound:Sound = new Sound();
  2. my_sound.attachSound("mySoundID");
  3. my_sound.onSoundComplete = function() {
  4.   trace("mySoundID completed");
  5. };
  6. my_sound.start();
Usage 2: The following example uses a named function:
ActionScript:
  1. function callback1() {
  2.   trace("mySoundID completed");
  3. }
  4. var my_sound:Sound = new Sound();
  5. my_sound.attachSound("mySoundID");
  6. my_sound.onSoundComplete = callback1;
  7. my_sound.start();
See also
Sound.onLoad
janoshnosh ist offline   Mit Zitat antworten
Alt 13-08-2005, 17:34   #3 (permalink)
Neuer User
 
Registriert seit: Aug 2005
Beiträge: 23
danke

kann ich auch irgendwie anzeigen lassen
a) wie lang der sound ist?
und
b) wie lange er schon spielt?
Denjo132 ist offline   Mit Zitat antworten
Alt 13-08-2005, 17:51   #4 (permalink)
:Void
 
Benutzerbild von janoshnosh
 
Registriert seit: Jun 2005
Ort: börlin
Beiträge: 931
ich mach mal weiter mit dem strgC+strgV spiel
Zitat:
Sound.position
Availability
Flash Player 6.

Usage

my_sound.position:Number

Description
Read-only property; the number of milliseconds a sound has been playing. If the sound is looped, the position is reset to 0 at the beginning of each loop.

Example
See Sound.duration for a sample usage of this property.

See Also
Sound.duration
Zitat:
Sound.duration
Availability
Flash Player 6.

Usage

my_sound.duration:Number

Description

Read-only property; the duration of a sound, in milliseconds.

Example

The following example loads a sound and displays the duration of the sound file in the Output panel. Add the following ActionScript to your FLA or AS file.
ActionScript:
  1. var my_sound:Sound = new Sound();
  2. my_sound.onLoad = function(success:Boolean) {
  3.   var totalSeconds:Number = this.duration/1000;
  4.   trace(this.duration+" ms ("+Math.round(totalSeconds)+" seconds)");
  5.   var minutes:Number = Math.floor(totalSeconds/60);
  6.   var seconds = Math.floor(totalSeconds)%60;
  7.   if (seconds<10) {
  8.     seconds = "0"+seconds;
  9.   }
  10.   trace(minutes+":"+seconds);
  11. };
  12. my_sound.loadSound("song1.mp3", true);
The following example loads several songs into a SWF file. A progress bar, created using the Drawing API, displays the loading progress. When the music starts and completes loading, information displays in the Output panel. Add the following ActionScript to your FLA or AS file.
ActionScript:
  1. var pb_height:Number = 10;
  2. var pb_width:Number = 100;
  3. var pb:MovieClip = this.createEmptyMovieClip("progressBar_mc", this.getNextHighestDepth());
  4. pb.createEmptyMovieClip("bar_mc", pb.getNextHighestDepth());
  5. pb.createEmptyMovieClip("vBar_mc", pb.getNextHighestDepth());
  6. pb.createEmptyMovieClip("stroke_mc", pb.getNextHighestDepth());
  7. pb.createTextField("pos_txt", pb.getNextHighestDepth(), 0, pb_height, pb_width, 22);
  8.  
  9. pb._x = 100;
  10. pb._y = 100;
  11.  
  12. with (pb.bar_mc) {
  13.   beginFill(0x00FF00);
  14.   moveTo(0, 0);
  15.   lineTo(pb_width, 0);
  16.   lineTo(pb_width, pb_height);
  17.   lineTo(0, pb_height);
  18.   lineTo(0, 0);
  19.   endFill();
  20.   _xscale = 0;
  21. }
  22. with (pb.vBar_mc) {
  23.   lineStyle(1, 0x000000);
  24.   moveTo(0, 0);
  25.   lineTo(0, pb_height);
  26. }
  27. with (pb.stroke_mc) {
  28.   lineStyle(3, 0x000000);
  29.   moveTo(0, 0);
  30.   lineTo(pb_width, 0);
  31.   lineTo(pb_width, pb_height);
  32.   lineTo(0, pb_height);
  33.   lineTo(0, 0);
  34. }
  35.  
  36. var my_interval:Number;
  37. var my_sound:Sound = new Sound();
  38. my_sound.onLoad = function(success:Boolean) {
  39.   if (success) {
  40.     trace("sound loaded");
  41.   }
  42. };
  43. my_sound.onSoundComplete = function() {
  44.   clearInterval(my_interval);
  45.   trace("Cleared interval");
  46. }
  47. my_sound.loadSound("song3.mp3", true);
  48. my_interval = setInterval(updateProgressBar, 100, my_sound);
  49.  
  50. function updateProgressBar(the_sound:Sound):Void {
  51.   var pos:Number = Math.round(the_sound.position/the_sound.duration*100);
  52.   pb.bar_mc._xscale = pos;
  53.   pb.vBar_mc._x = pb.bar_mc._width;
  54.   pb.pos_txt.text = pos+"%";
  55. }
See Also
Sound.position
darfst auch gerne mal selber F1 in flash drücken und dir die sound-methoden anschauen.
gruß janosch
janoshnosh ist offline   Mit Zitat antworten
Alt 13-08-2005, 17:55   #5 (permalink)
Neuer User
 
Registriert seit: Aug 2005
Beiträge: 23
hehe... ich wusste nich das das duration heißt aber ich hab vorher ja gesucht

war auch meine letzte frage (für heute)

danke nochma
Denjo132 ist offline   Mit Zitat antworten
Alt 13-08-2005, 18:01   #6 (permalink)
Neuer User
 
Registriert seit: Aug 2005
Beiträge: 23
oder auch nich... ich hab kein plan wie ich das jetzt in ein dynamisches textfeld schreiben lasse... also das das textfeld anzeigt wie viele sekunden schon vorbei sind
Denjo132 ist offline   Mit Zitat antworten
Alt 13-08-2005, 18:20   #7 (permalink)
:Void
 
Benutzerbild von janoshnosh
 
Registriert seit: Jun 2005
Ort: börlin
Beiträge: 931
umn, ok

also mit der Sound.position eigenschaft ist es ja so, dass sie je nachdem, wann man sie aufruft, einen anderen wert liefert. logisch, da der sound ja abspielt und sich die eigenschaft dadurch verändert. wenn du nun in deinem textfeld die zeit anzeigen willst, musst du also ständig diese eigenschaft von deinem sound-objekt abfragen.

am besten du hast einen MC (dein_mc) in dem sich das textfeld (position_txt) befindet. diesem MC gibst du einen onEnterFrame handler, der bei jedem frameaufruf (also bei 20fps 20 mal pro sekunde) die eigenschaft deines sound-objekts (laerm_sound) abfragt und an das textfeld gibt.
ActionScript:
  1. dein_mc.onEnterFrame = function () {
  2. this.position_txt.text = laerm_sound.position;
  3. }
nun solltest du aber, wenn kein sound gespielt wird, den onEnterFrame handler löschen (delete dein_mc.onEnterFrame), damit das ding nicht ewig weiter läuft, selbst wenn nix passiert. im obigen beispiel wird nun auch nur die restzeit in millisekunden angezeigt, aber so ungefähr kannst du das auf jeden fall machen.

gruß janosch
janoshnosh ist offline   Mit Zitat antworten
Alt 13-08-2005, 18:31   #8 (permalink)
Neuer User
 
Registriert seit: Aug 2005
Beiträge: 23
ok.. ich probiers ma aus...
danke
Denjo132 ist offline   Mit Zitat antworten
Alt 13-08-2005, 19:27   #9 (permalink)
Neuer User
 
Registriert seit: Aug 2005
Beiträge: 23
es funzt... danke danke
kann man die zeit auch in sekunden anzeign lassn?
oder geht das nich?
Denjo132 ist offline   Mit Zitat antworten
Alt 13-08-2005, 19:44   #10 (permalink)
:Void
 
Benutzerbild von janoshnosh
 
Registriert seit: Jun 2005
Ort: börlin
Beiträge: 931
es sind ja millisekunden, wenn du sie also durch tausen teilst, hast du sekunden, wenn du sie dann noch rundest hast du echte sekunden. minuten:sekunden (mm:ss) anzeige ist da ein bisschen more tricky.

sonst halt einfach:
position_txt.text = Math.round(laerm_sound.position/1000);

gruß janosch
janoshnosh ist offline   Mit Zitat antworten
Alt 13-08-2005, 19:59   #11 (permalink)
Neuer User
 
Registriert seit: Aug 2005
Beiträge: 23
es funzt schon wieder
super naja danke nochma

wüsstest du denn wies geht die minuten und sekunden anzeigen zu lassen?

Geändert von Denjo132 (13-08-2005 um 20:06 Uhr)
Denjo132 ist offline   Mit Zitat antworten
Alt 15-08-2005, 00:44   #12 (permalink)
:Void
 
Benutzerbild von janoshnosh
 
Registriert seit: Jun 2005
Ort: börlin
Beiträge: 931
oh sorry ist mir entgangen, dass es hier schon weiter ging
ja hier eine kleine funktion mit beispielaufruf:
ActionScript:
  1. function hhmmss (ms) {
  2.     var t = ms/1000;
  3.     var hh = '0';
  4.     var mm = Math.floor(t/60) + '';
  5.     var ss = Math.round(t - mm*60) + '';
  6.     if (ss.length==1) ss = '0' + ss;
  7.     if (mm.length >2) {
  8.         hh = Math.floor(mm/60) + '';
  9.         mm = Math.round(mm - hh*60) + '';
  10.     }
  11.     if (mm.length==1) mm = '0' + mm;
  12.     return hh+':'+mm+':'+ss;
  13. }
  14.  
  15. trace(hhmmss(3000));        //traces 0:00:03
  16. trace(hhmmss(36453456));    //traces 10:07:33
  17.  

also die sound.position dann in deinem fall als hhmmss(sound.position) ausgeben lassen - alles was als millisekunde reinkommt, kommt im hh:mm:ss format raus.
bzw. so, um nur mm:ss zu erhalten:
ActionScript:
  1. function mmss (ms) {
  2.     var t = ms/1000;
  3.     var mm = Math.floor(t/60) + '';
  4.     var ss = Math.round(t - mm*60) + '';
  5.     if (ss.length==1) ss = '0' + ss;
  6.     return mm+':'+ss;
  7. }
noch was?
gruß janosch
janoshnosh ist offline   Mit Zitat antworten
Alt 17-08-2005, 14:20   #13 (permalink)
Neuer User
 
Registriert seit: Aug 2005
Beiträge: 23
ne danke das war erstma das was ich wissn will
danke schön
Denjo132 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:02 Uhr.

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


Copyright ©1999 – 2012 Marc Thiele