dcsimg
A Flash Developer Resource Site

Results 1 to 2 of 2

Thread: New function split()

  1. #1
    KoolMoves Moderator blanius's Avatar
    Join Date
    Jul 2001
    Location
    Atlanta GA
    Posts
    5,244

    New function split()

    I was testing something here and found that the AS command Split() is not available in 3dfa This is a VERY usefull command as it lets you send an array from the server as a comma delimited string and turn it back into an array in flash.
    So being me I just wrote my own function to do the same thing.

    Example call
    code:

    string1="one,two,three,four,five,six,seven,hi there"
    myarray=root.split(string1,",")
    trace("array length="+myarray.length)
    for (x=0;x<myarray.length;x++){
    trace(myarray[x])
    }



    where string1 is the string with the data in it. You can use any delimiter but comma is commonly used.

    Heres the function
    code:

    function split(BL_string,delimiter){
    BL_array=new Array()
    /* Function to replace missing split functionality
    call it myArray=root.split(string,delimiter)
    */
    //Get first element in array
    first=BL_string.indexOf(delimiter,0);
    end=BL_string.indexOf(delimiter,first+1);
    BL_array[0]=BL_string.substr(0,first);

    //Now get the rest of the elements
    start=first
    idx=1
    while(start<>-1){
    end=BL_string.indexOf(delimiter,start+1);
    if (end==-1){
    BL_array[idx]=BL_string.slice(start+1,BL_string.length);
    }else{
    BL_array[idx]=BL_string.substr(start+1,(end-start-1));
    }
    idx++
    start=BL_string.indexOf(delimiter,start+1);

    }
    return BL_array

    }//end if split function

    Last edited by blanius; 12-30-2004 at 12:38 PM.

  2. #2
    KoolMoves Moderator blanius's Avatar
    Join Date
    Jul 2001
    Location
    Atlanta GA
    Posts
    5,244
    Odd for some reason this function is causing a problem on export so don't use it till I figure it out.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center