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

This is a question about AS3.0 split

Explorer ,
Apr 18, 2023 Apr 18, 2023

Copy link to clipboard

Copied

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

 

Views

530

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

Copy link to clipboard

Copied

in Animate

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

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

Copy link to clipboard

Copied

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

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

Copy link to clipboard

Copied

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

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

Copy link to clipboard

Copied

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
}

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

Copy link to clipboard

Copied

Thanks for the solution

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

Copy link to clipboard

Copied

LATEST

you're welcome.

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

Copy link to clipboard

Copied

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

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

Copy link to clipboard

Copied

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

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