SoundScape used by GoogleStaticMap takimo forked:3favorite:1lines:154license : All rights reserved modified : 2009-02-27 14:48:17 Embed Tweet package { import flash.display.Sprite; import flash.display.Loader; import flash.net.URLRequest; import flash.media.Sound; import flash.media.SoundChannel; import flash.events.Event; import flash.events.MouseEvent; public class GoogleStaticMapSample extends Sprite { /* * 絶賛作りかけ中 * api_keyはhttp://wonderfl.kayac.comのもの */ private var _url:String = "http://maps.google.com/staticmap?center=40.714728,-73.998672&zoom=16&size=465x465&key=ABQIAAAAPtBEKmwoSb1mcvueuEPWcxQhT1D-zBzSaMzrPqwMx30VwtznthShYcaY4l9_1DFeYdw1X5i-GB7yDw"; private var _bgmURL:String = "http://movie.geocities.jp/mastergreatmario/smb3_w1.mp3"; private var _soundURL:String = "http://ia311209.us.archive.org/2/items/Audio-Music-Treasures/SMB3_Jump.mp3"; private var _popupBox:PopupBox = new PopupBox(); private var _sound:Sound = new Sound(); private var _bgm:SoundChannel; public function GoogleStaticMapSample() { // GoogleMapとpopupのBoxを配置 init(); // SoundScapeを作って配置 setSoundScape(); // BGMを生成 var request:URLRequest = new URLRequest(_bgmURL); _sound.load(request); _bgm = _sound.play(); // BGMをループさせる _bgm.addEventListener(Event.SOUND_COMPLETE, handleBGMComplete); } private function init():void { var request:URLRequest = new URLRequest(_url); var map:Loader = new Loader(); map.load(request); addChild(map); _popupBox = new PopupBox(0x000000); _popupBox.visible = false; addChild(_popupBox); } private function setSoundScape():void { var circle1:SoundScape = new SoundScape(_soundURL, 0x2E95A3, "Super Mario"); circle1.x = 170; circle1.y = 200; circle1.addEventListener(MouseEvent.ROLL_OVER, handleOver); circle1.addEventListener(MouseEvent.ROLL_OUT, handleOut); circle1.addEventListener(MouseEvent.CLICK, handleClick); addChild(circle1); } private function handleOver(e:MouseEvent):void { _popupBox.x = e.target.x - 10; _popupBox.y = e.target.y - 32; _popupBox.text = e.target.description; _popupBox.visible = true; } private function handleOut(e:MouseEvent):void { _popupBox.visible = false; } private function handleClick(e:MouseEvent):void { // 再生中かどうかチェック if(e.target.status) { e.target.stop(); } else { e.target.play(); } } private function handleBGMComplete(e:Event):void { // 再生をもう一度して再生終了時のイベントにこのfunction(リスナー)を登録 = 永遠にループ _bgm = _sound.play(); _bgm.addEventListener(Event.SOUND_COMPLETE, handleBGMComplete); } } } import flash.display.Sprite; import flash.text.TextField; import flash.text.TextFormat; class PopupBox extends Sprite { private var _textArea:TextField; public function PopupBox(color:int = 0x000000, description:String = ""):void { var box:Sprite = new Sprite(); box.graphics.beginFill(color); box.graphics.drawRect(0, 0, 130, 18); box.alpha = 0.2; _textArea = new TextField(); _textArea.textColor = 0xFFFFFF; _textArea.x = 3; _textArea.y = 0; _textArea.width = 127; _textArea.height = 18; addChild(box); addChild(_textArea); } public function set text(text:String):void { _textArea.text = text; } } import flash.display.Sprite; import flash.events.Event; import flash.events.MouseEvent; import flash.events.IOErrorEvent; import flash.media.Sound; import flash.media.SoundTransform import flash.media.SoundChannel; import flash.net.URLRequest; class SoundScape extends Sprite { private var _sound:Sound = new Sound(); private var _song:SoundChannel; private var _position:int; private var _description:String = ""; private var _playStatus:int = 0; private var _volume:SoundTransform = new SoundTransform(); public function SoundScape(soundURL:String, color:int = 0x2E95A3, description:String = null):void { this.graphics.beginFill(color); this.graphics.drawCircle(0, 0, 10); this.buttonMode = true; _description = description; var request:URLRequest = new URLRequest(soundURL); _sound.addEventListener(IOErrorEvent.IO_ERROR, handleIOError); _sound.load(request); } public function get description():String { return _description; } private function handleIOError(e:IOErrorEvent):void { } private function handleSoundComplete(e:Event):void { _song = _sound.play(); _song.addEventListener(Event.SOUND_COMPLETE, handleSoundComplete); } public function get status():int { return _playStatus; } public function play():void { _song = _sound.play(); _song.addEventListener(Event.SOUND_COMPLETE, handleSoundComplete); _playStatus = 1; } public function stop():void { _song.stop(); _song.soundTransform = _volume; _song.removeEventListener(Event.SOUND_COMPLETE, handleSoundComplete); _playStatus = 0; } } Code Fullscreen Preview Fullscreen paq IOErrorEvent.SOUND_COMPLETE soundTransform stop buttonMode IOErrorEvent.IO_ERROR IOErrorEvent URLRequest removeEventListener color addEventListener String Sprite int sort new page view favorite forked pv142 forked from: SoundScape used b.. 2008tomonori forked:0 favorite:0lines:154 (diff:1) pv183 forked from: SoundScape used b.. 2008tomonori forked:0 favorite:0lines:154 (diff:1) pv0 forked from: SoundScape used b.. dbsh3517 forked:0 favorite:0lines:154 (diff:1)