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

This is a question about AS3.0 split

Explorer ,
Apr 18, 2023 Apr 18, 2023

I wrote the code as below, but the list is not separated and saved in the array sm.
What's wrong with my code?
Any help would be appreciated.

var sm:Array = [];

var request:URLRequest = new URLRequest("http://.............../Text/soundList.txt");
// txt file : "a,b,c,d,.........."
var loader:URLLoader = new URLLoader();
loader.load(request);
loader.addEventListener(Event.COMPLETE, completeHandler);

function completeHandler(event:Event):void {
	var str:String = event.target.data;
	//trace(str);  // "a,b,c,d,..............."
	sm = str.split(",");  // comma
	//trace(sm);  // "a,b,c,d,..............."
}
trace(sm.length); // result => 0

 

761
Translate
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
Explorer ,
Apr 18, 2023 Apr 18, 2023

in Animate

Is there any way to insert(or import) a fla file from another remote directory into the fla file?

Translate
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
Engaged ,
Apr 18, 2023 Apr 18, 2023

I think, you check the result before assign a value to the array.
completeHandler() executes asynchronously with a big delay, so to check the actual result, AFTER the assignment, you need to put the trace() within the completeHandler() function, right after the line

sm = str.split(",");

 

 

- Vlad: UX and graphic design, Flash user since 1998
Member of Flanimate Power Tools team - extensions for character animation
Translate
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
Explorer ,
Apr 18, 2023 Apr 18, 2023

Thank you so much.
"completeHandler() executes asynchronously with a big delay"
I would like to know why

Translate
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
Community Expert ,
Apr 18, 2023 Apr 18, 2023

sm is fine after completeHandler executes. but you're not checking sm's length in that completeHandler. 

 

when you check sm it is equal to  []. that is the problem, and this is the solution:

 

function completeHandler(event:Event):void {
	var str:String = event.target.data;
	//trace(str);  // "a,b,c,d,..............."
	sm = str.split(",");  // comma
	//trace(sm);  // "a,b,c,d,..............."
trace(sm.length); // result => 0
}
Translate
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
Explorer ,
Apr 18, 2023 Apr 18, 2023

Thanks for the solution

Translate
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
Community Expert ,
Apr 18, 2023 Apr 18, 2023
LATEST

you're welcome.

Translate
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
Community Expert ,
Apr 18, 2023 Apr 18, 2023

Hi.

 

Reading data from the file system usually takes seconds or minutes. So you can't rely on having the data you're requesting in the same tick.

 

Regards,

JC

Translate
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
Explorer ,
Apr 18, 2023 Apr 18, 2023

Thank you so much
It was my mistake, thanks a lot for advice

Translate
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