// // Licensed under the MIT License // // Copyright (C) 2008 TAKANAWA Tomoaki (http://nutsu.com) and // Spark project (www.libspark.org) // // 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. // package snapfit.media { import flash.media.Sound; import flash.media.SoundLoaderContext; import flash.media.SoundTransform; import flash.media.SoundChannel; import flash.net.URLRequest; import snapfit.events.adapters.FSoundAdapter; /** * FSound * * @author nutsu */ public class FSound extends Sound { private var _adapter:FSoundAdapter; private var _channel:SoundChannel; private var _channel_flg:Boolean; /** * FSound * * @param stream * @param context */ public function FSound( stream:URLRequest = null, context:SoundLoaderContext = null ) { super( stream, context ); _adapter = new FSoundAdapter( this ); _channel_flg = false; } public function get event():FSoundAdapter { return _adapter; } override public function play( startTime:Number = 0, loops:int = 0, sndTransform:SoundTransform = null ):SoundChannel { _channel = super.play( startTime, loops, sndTransform ); if ( _channel ) _channel_flg = true; return _channel; } //---------------------------------------------------------------------------------------------- SoundChannel /** * SoundChannel */ public function get channel():SoundChannel { return _channel; } /** * SoundTransform */ public function get soundTransform():SoundTransform { if ( _channel_flg ) return _channel.soundTransform; else return null; } /** * position */ public function get position():Number { if ( _channel_flg ) return _channel.position; else return NaN; } /** * leftPeak */ public function get leftPeak():Number { if ( _channel_flg ) return _channel.leftPeak; else return NaN; } /** * rightPeak */ public function get rightPeak():Number { if ( _channel_flg ) return _channel.rightPeak; else return NaN; } //---------------------------------------------------------------------------------------------- SoundTransform /** * pan */ public function get pan():Number { if ( _channel_flg ) return _channel.soundTransform.pan; else return NaN; } public function set pan( value:Number ):void { if ( _channel_flg ) { var st:SoundTransform = _channel.soundTransform; st.pan = value; _channel.soundTransform = st; } } /** * volume */ public function get volume():Number { if ( _channel_flg ) return _channel.soundTransform.volume; else return NaN; } public function set volume( value:Number ):void { if ( _channel_flg ) { var st:SoundTransform = _channel.soundTransform; st.volume = value; _channel.soundTransform = st; } } } }