System.useCodePage = false;
var urlLoader:URLLoader;
var loader:Loader;
var Bis:Boolean = false;
var pos:int = 0;
var cnt:int = 0;
var xml:XML;
var mcarr:Array = new Array();
urlLoader=new URLLoader();
var urlRequest: URLRequest = new URLRequest();
var urlVariables:URLVariables = new URLVariables();
var soundobj:Sound;
var channel:SoundChannel;
urlRequest.url = “http://www.titorus.com/bgmread.php”;
urlRequest.data = urlVariables;
//System.useCodePage= true;
btplay.addEventListener(MouseEvent.CLICK,onclick);
btpause.addEventListener(MouseEvent.CLICK,onpause);
btstop.addEventListener(MouseEvent.CLICK,onstop);
urlLoader.addEventListener( Event.COMPLETE, onComplete );
urlLoader.load( urlRequest );
function onclick(e:MouseEvent):void
{
trace(“플래이”);
if (pos > 0)
{
soundobj.play(pos);
}
else
{
var item:Object = cb.selectedItem;
if (cb.selectedIndex > -1)
{
trace(item.label);
soundobj= new Sound();
// trace(item.label)
soundobj.load(new URLRequest(“http://www.titorus.com/bgm/”+encodeURI(item.label)));
soundobj.addEventListener(IOErrorEvent.IO_ERROR, errorHandler);
channel = new SoundChannel();
channel = soundobj.play();
channel.addEventListener(Event.SOUND_COMPLETE, oo);
Bis = true;
}
}
}
function onpause(e:MouseEvent):void
{
trace(“일시정지”);
pos = channel.position;
channel.stop();
}
function onstop(e:MouseEvent):void
{
trace(“정지”);
pos = 0;
channel.stop();
}
function errorHandler(event:IOErrorEvent):void
{
trace(“Couldn’t load the file ” + event.text);
}
function songSelected(e:Event):void
{
// var cb:ComboBox = event.currentTarget as ComboBox;
var item:Object = cb.selectedItem;
trace(cb.selectedIndex);
cnt = cb.selectedIndex;
if (cb.selectedIndex > -1)
{
// trace(item.label)
if (Bis == true)
{
channel.stop();
Bis = false;
}
soundobj= new Sound();
soundobj.load(new URLRequest(“http://www.titorus.com/bgm/”+encodeURI(item.label)));
soundobj.addEventListener(IOErrorEvent.IO_ERROR, errorHandler);
channel = new SoundChannel();
channel = soundobj.play();
channel.addEventListener(Event.SOUND_COMPLETE, oo);
Bis = true;
}
}
function onComplete( e: Event ):void
{
xml = new XML(urlLoader.data);
trace( xml.toXMLString() );
for (var j:int=0; j<xml.child(“data”).length(); j++)
{
cb.addItem({label:(xml.child([j]).file)});
mcarr.push(xml.child([j]).file);
cb.addEventListener(Event.CHANGE, songSelected);
}
var item:Object = cb.selectedItem;
soundobj= new Sound();
trace(“xml :”+ xml.child([cnt]).file);
var ii:String = xml.child([cnt]).file;
var ss:String = “http://www.titorus.com/bgm/” + encodeURI(ii);
trace(“ss:”+ ss );
soundobj.load(new URLRequest(ss));
soundobj.addEventListener(IOErrorEvent.IO_ERROR, errorHandler);
channel = new SoundChannel();
channel = soundobj.play();
channel.addEventListener(Event.SOUND_COMPLETE, oo);
Bis = true;
}
function oo(e:Event):void
{
trace(“완료”);
if (cb.rowCount <= cnt)
{
cnt = 0;
cb.selectedIndex = cnt;
}
else
{
cnt++;
cb.selectedIndex = cnt;
}
if (Bis == true)
{
channel.stop();
Bis = false;
}
soundobj= new Sound();
soundobj.load(new URLRequest(“http://www.titorus.com/bgm/”+encodeURI(xml.child([cnt]).file)));
soundobj.addEventListener(IOErrorEvent.IO_ERROR, errorHandler);
channel = new SoundChannel();
channel = soundobj.play();
channel.addEventListener(Event.SOUND_COMPLETE, oo);
Bis = true;
if (cnt == xml.child(“data”).length())
{
cnt = 0;
}
}