Skip to main content
Inspiring
April 18, 2023
Question

This is a question about AS3.0 split

  • April 18, 2023
  • 2 replies
  • 716 views

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

 

    This topic has been closed for replies.

    2 replies

    Vladin M. Mitov
    Inspiring
    April 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 1998Member of Flanimate Power Tools team - extensions for character animation
    Inspiring
    April 18, 2023

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

    kglad
    Community Expert
    Community Expert
    April 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
    }
    
    Inspiring
    April 18, 2023

    in Animate

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