Skip to main content
Inspiring
Apr 18, 2023 7:23 AM UTC
Question

This is a question about AS3.0 split

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 is closed to new replies. Start a new post to keep the conversation going.

    8 replies

    Vladin M. Mitov
    Inspiring
    Apr 18, 2023 9:30 AM UTC

    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(",");

     

     

    Translate
    - Vlad: UX and graphic design, Flash user since 1998Member of Flanimate Power Tools team - extensions for character animation
    Inspiring
    Apr 18, 2023 1:45 PM UTC

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

    Translate
    kglad
    Community Expert
    Community Expert
    Apr 18, 2023 1:47 PM UTC

    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
    Inspiring
    Apr 18, 2023 9:25 AM UTC

    in Animate

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

    Translate