Forked from: kotobuki's Simple Sound Player: Physical Button diff:41 Simple Sound Player: Photo Reflector kotobuki forked:4favorite:0lines:43license : MIT License modified : 2009-12-07 16:20:52 Embed Tweet // forked from kotobuki's Simple Sound Player: Physical Button // forked from kotobuki's Simple Sound Player package { import flash.display.Sprite; import flash.events.Event; import flash.media.Sound; import flash.net.URLRequest; import flash.utils.getTimer; import funnel.*; import funnel.ui.*; [SWF(backgroundColor="0x808080")] public class SimpleSoundPlayer extends Sprite { private const URL_OF_SOUND_FILE:String = "http://www.iamas.ac.jp/~mayfair/tmp/snare.mp3"; private var _sound:Sound; private var _gainer:Gainer; private var _signalScope:SignalScope; private var _lastPlayed:int = 0; private var _sensorPin:Pin; [SWF(backgroundColor="0x808080")] public function SimpleSoundPlayer() { _sound = new Sound(); _sound.addEventListener(Event.COMPLETE, onLoadComplete); _sound.load(new URLRequest(URL_OF_SOUND_FILE)); _gainer = new Gainer(); _sensorPin = _gainer.analogInput(0); // センサからの入力を確認するためのSignalScopeを用意します _signalScope = new SignalScope(10, 10, 200, "Photo Reflector"); addChild(_signalScope); addEventListener(Event.ENTER_FRAME, onEnterFrame); } private function onLoadComplete(e:Event):void { // サウンドの準備ができたらセンサ入力に対してにSetPointフィルタをセットし、 // 0→1への変化が起きた時に呼ぶイベントリスナをセットします _sensorPin.addFilter(new SetPoint([0.8, 0.05])); _sensorPin.addEventListener(PinEvent.FALLING_EDGE, onRisingEdge); } private function onEnterFrame(e:Event):void { // 毎フレームごとにSignalScopeを更新します _signalScope.update(_sensorPin); } private function onRisingEdge(e:PinEvent):void { // 前回の再生から一定時間(この場合は200ms)が経過していたら再生を始めます var now:int = getTimer(); if ((now - _lastPlayed) > 200) { _sound.play(30); _lastPlayed = now; } } } } Code Fullscreen Preview Fullscreen gainer physical play addEventListener Event addChild Event.ENTER_FRAME String Sprite int sort new page view favorite forked pv222 forked from: Simple Sound Play.. kotobuki forked:0 favorite:0lines:43 (diff:1) pv246 forked from: Simple Sound Play.. WTRKBR7018 forked:0 favorite:0lines:51 (diff:20) pv171 forked from: Simple Sound Play.. kotobuki forked:0 favorite:0lines:45 (diff:13) pv180 forked from: Simple Sound Play.. pao_telecaster forked:0 favorite:0lines:44 (diff:18)