A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: Audio Syncing

  1. #1
    Senior Member
    Join Date
    Dec 2002
    Location
    Netherlands
    Posts
    1,632

    Audio Syncing

    Here's an example of how multiple events could be added to a sound file. As you can see it can both set properties of an object and execute object functions with a supplied parameter array.
    It may need some polishing but it's a start.

    Code:
    // Extending the sound object
    
    Sound.prototype.setSoundEvents = function( events, accuracy ){
      this.events = events;
      this.current_event = 0;
      if (this.interval_id != null) clearInterval(this.interval_id);
      this.interval_id = setInterval(this, 'sync', accuracy);
    }
    
    Sound.prototype.sync = function(){
      if (this.position >= this.events[this.current_event].sp){
        var event = this.events[this.current_event];
        if (event.f != null){
          var func = event.o[event.f];
          func.apply(event.o, event.p );
        } else if (event.p != null){
          event.o[event.p] = event.v;
        }
        this.current_event = this.current_event + 1;
        if (this.current_event == this.events.length) clearInterval(this.interval_id);
        this.sync();
      }
    }
    
    // using it
    
    mySoundEvents = new Array();
    
    mySoundEvents.push ( { sp:1500, o:_root.mc1, f:'gotoAndStop', p:['eeks'] } );
    mySoundEvents.push ( { sp:2000, o:_root.mc1, f:'gotoAndStop', p:[1] } );
    mySoundEvents.push ( { sp:3000, o:_root.mc2, p:'_visible', v:false } );
    mySoundEvents.push ( { sp:3500, o:_root.mc2, p:'_visible', v:true } );
    
    mySoundEvents.sortOn('sp');
    
    mySound = new Sound();
    mySound.setSoundEvents( mySoundEvents, 50 ); accuracy 50 msec
    mySound.loadSound('myMP3file.mp3',true);
    mySound.start();

  2. #2
    undead creature necromanthus's Avatar
    Join Date
    Feb 2002
    Location
    ROM
    Posts
    1,890
    The main problem is that because of the missing symbol-library (and the sound object) it doesn't work for internal sounds.
    For loaded (external) sound files only.
    Anyway, well done Wilbert.

  3. #3
    Senior Member
    Join Date
    Jun 2000
    Posts
    3,512
    I'll start the implementation of a symbol library with sounds first.

  4. #4
    undead creature necromanthus's Avatar
    Join Date
    Feb 2002
    Location
    ROM
    Posts
    1,890
    Originally posted by Bob Hartzell
    I'll start the implementation of a symbol library with sounds first.
    MovieClips are much more important.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center