• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

AS3.0 URL Loader and Delay

Explorer ,
Apr 24, 2023 Apr 24, 2023

Copy link to clipboard

Copied

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()

 

Views

144

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Engaged , Apr 24, 2023 Apr 24, 2023

Hi,

I recommend adding trace() statements to several key places in your code to determine the execution sequence. You'll find that the code you want to execute "after" is actually being executed before the completeHandler() function, despite being written further down in the script file.

Additionally, as a general best practice, I recommend organizing your code into classes and functions. This will help improve code structure and readability, and ensure that the execution sequence is more easily m

...

Votes

Translate

Translate
Engaged ,
Apr 24, 2023 Apr 24, 2023

Copy link to clipboard

Copied

LATEST

Hi,

I recommend adding trace() statements to several key places in your code to determine the execution sequence. You'll find that the code you want to execute "after" is actually being executed before the completeHandler() function, despite being written further down in the script file.

Additionally, as a general best practice, I recommend organizing your code into classes and functions. This will help improve code structure and readability, and ensure that the execution sequence is more easily managed and understood.

 

 

- Vlad: UX and graphic design, Flash user since 1998
Member of Flanimate Power Tools team - extensions for character animation

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines