AS3.0 URL Loader and Delay
Download the music list (text file) from the remote directory
I want to make a music list.
After "A codes" have been fully executed, "B codes and below"
Is there any way to run it?
thank you
var n: uint;
var sm:Array = [];
musicList => textField
musicList_btn =>musicList button
//=== A codes =======================================
var request:URLRequest = new URLRequest("http://......./Text/soundList.txt");
var loader:URLLoader = new URLLoader();
loader.load(request);
loader.addEventListener(Event.COMPLETE, completeHandler);
function completeHandler(event:Event):void {
var str:String = event.target.data;
sm = str.split(",");
sm.sort();
for (var i: uint = 0; i < sm.length; i++) {
musicList.appendText(sm[i]+"\n");
}
}
//=== B codes ======================================
musicList_btn.addEventListener(MouseEvent.CLICK, musicListSelect);
var musicListOK: Boolean = false;
function musicListSelect(evt: MouseEvent): void {
musicListOK = !musicListOK;
if (musicListOK) {
musicList.addEventListener(MouseEvent.CLICK, selectMusic);
} else {
musicList.removeEventListener(MouseEvent.CLICK, selectMusic);
}
}
function selectMusic(e: MouseEvent): void {
var index: uint = musicList.getLineIndexAtPoint(e.localX, e.localY);
if (index >= musicList.bottomScrollV) return;
if ((index != -1) && (index != n)) {
n = index;
musicPlay(sm[n]);
}
}
//== next codes =====================
n = int(Math.random() * (sm.length - 1)); //random play
musicPlay(sm[n]);
//=== error ====================
TypeError: Error #2007: Parameter text must be non-null.
at flash.text::TextField/set text()
at FiatSound_001_fla::MainTimeline/musicPlay()
at FiatSound_001_fla::MainTimeline/frame1()
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at FiatSound_001_fla::MainTimeline/soundCompleteHandler()
