import flash.external.ExternalInterface; class Bridge { static function main() { var sounds = {}; /*** register after we've notified the flash bridge that this movie is ready, the bridge will notify us of the identifier for our handler object for the window.flashBridge.receive function. */ var id; ExternalInterface.addCallback('register', null, function (idValue) { id = idValue; }); /*** send call a function on the connected receiver object */ var send = function (method) { ExternalInterface.call( '__flash__bridge.receive', id, method, arguments.slice(1) ); }; /* a memoized sound constructor */ var getSound = function (url) { /* check the memos */ if (sounds[url] === undefined) { sounds[url] = new Sound(); } var sound = sounds[url]; /* set up event observers */ sound.onSoundComplete = function () { send('finished', url); } sound.onLoad = function () { send('ready', url); }; sound.onID3 = function () { send('id3', url, sound.id3); }; return sound; }; /*** load */ ExternalInterface.addCallback('load', null, function (url, stream, play) { var sound = getSound(url); sound.loadSound(url, true); if (!play) sound.stop(); }); /*** unload */ ExternalInterface.addCallback('unload', null, function (url) { sounds[url] = undefined; }); /*** stop */ ExternalInterface.addCallback('stop', null, function (url) { getSound(url).stop(); }); /*** start */ ExternalInterface.addCallback('start', null, function ( url, pos, loops ) { getSound(url).start(pos / 1000, loops); }); /*** setPos */ ExternalInterface.addCallback('setPos', null, function ( url, pos ) { getSound(url).setPos(pos); }); /*** getPos */ ExternalInterface.addCallback('getPos', null, function (url) { return getSound(url).getPos(); }); /*** getDuration */ ExternalInterface.addCallback('getDuration', null, function (url) { return getSound(url).getDuration(); }); /*** setPan */ ExternalInterface.addCallback( 'setPan', null, function (url, pan) { getSound(url).setPan(pan); }); /*** setTransform */ ExternalInterface.addCallback('setTransform', null, function ( url, transform ) { getSound(url).setTransform(transform); }); /*** setVolume */ ExternalInterface.addCallback('setVolume', null, function (url, volume) { getSound(url).setVolume(volume); }); /*** getVolume */ ExternalInterface.addCallback('getVolume', null, function (url, volume) { return getSound(url).getVolume(volume); }); /*** getId3 */ ExternalInterface.addCallback('getId3', null, function (url) { /* getId3() does not work */ return getSound(url).id3; }); /*** getBytesLoaded */ ExternalInterface.addCallback('getBytesLoaded', null, function (url) { return getSound(url).getBytesLoaded(); }); /*** getBytesTotal */ ExternalInterface.addCallback('getBytesTotal', null, function (url) { return getSound(url).getBytesTotal(); }); /*** getProgress */ ExternalInterface.addCallback('getProgress', null, function (url, pos) { var sound = getSound(url); if (pos == undefined) pos = sound.getPos(); return pos / sound.getDuration() * sound.getBytesLoaded() / sound.getBytesTotal() ; }); ExternalInterface.call('__flash__bridge.ready'); }};