ホームに戻る
ActionScript3.0 サウンド
package{
import flash.display.Loader;
import flash.display.Sprite;
import flash.media.Sound;
import flash.display.BitmapData;
import flash.events.Event;
import flash.events.ProgressEvent;
import flash.net.URLRequest;
import flash.text.TextField;
[SWF(width="300", height="200", backgroundColor="0xFFFFFF")]
public class Main extends Sprite
{
private var text_field:TextField;
private var sound_obj:Sound;
public function Main():void
{
// テキストフィールドの準備
text_field = new TextField();
text_field.x = 0; // x 座標
text_field.y = 0; // y 座標
text_field.width = 300; // 幅
text_field.height = 200; // 高さ
addChild(text_field);
var url:URLRequest = new URLRequest("http://mniwa.web.fc2.com/mp3/song_b.mp3");
sound_obj = new Sound(url);
sound_obj.addEventListener(Event.OPEN,SoundOpenFunc);
sound_obj.addEventListener(ProgressEvent.PROGRESS,SoundProgressFunc);
sound_obj.addEventListener(Event.COMPLETE,SoundCompleteFunc);
}
private function SoundOpenFunc(e:Event):void
{
text_field.appendText("onOpen : ロード開始\n");
}
private function SoundProgressFunc(e:ProgressEvent):void
{
text_field.appendText("onProgress : ");
text_field.appendText(e.bytesTotal + " バイト中 ");
text_field.appendText(e.bytesLoaded + " バイト読み込み完了\n");
}
private function SoundCompleteFunc(e:Event):void
{
text_field.appendText("onComplete : ロード完了\n");
sound_obj.play();
}
}
}