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
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?
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(",");
Copy link to clipboard
Copied
Thank you so much.
"completeHandler() executes asynchronously with a big delay"
I would like to know why
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
}
Copy link to clipboard
Copied
Thanks for the solution
Copy link to clipboard
Copied
you're welcome.
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
Copy link to clipboard
Copied
Thank you so much
It was my mistake, thanks a lot for advice