/*file chiron src/sound.as */ /*preamble Copyright (c) 2002-2008 Kris Kowal MIT License The license terms are stated in full in and at the end of all source files. */ 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); }); /*** setPosition */ ExternalInterface.addCallback('setPosition', null, function ( url, pos ) { getSound(url).setPos(pos); }); /*** getPosition */ ExternalInterface.addCallback('getPosition', 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'); }}; /*license Legal ======= Chiron is a component of the Tale web-game project. See for a complete list of contributions and their licenses. All contributions are provided under permissive, non-viral licenses including MIT, BSD, Creative Commons Attribution 2.5, Public Domain, or Unrestricted. License ======= Copyright (c) 2002-2008 Kris Kowal MIT License MIT License ----------- Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */