A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: Array split

  1. #1
    Member
    Join Date
    Nov 2003
    Posts
    50

    Array split

    Hi forum,
    my asking is very simple ... i would like to put some delimiter within my array that provide data for comboBox component
    i have tried something like this:
    code:
    var actorsArray:Array = actorsData.split(rowdelimiter); //delimiter is ";" and it push records in new  row
    for (z=0; z<actorsArray.length; ++z){
    actorsArray = actorsArray[z].split(",");
    }
    actorsArray.unshift("default value for combo");
    pickLetter2_cmb.removeAll();
    pickLetter2_cmb.dataProvider = actorsArray;
    // select first item by default
    pickLetter2_cmb.selectedIndex = 0;


    but it doesn't work but rather give me result in combo as they are i.e.
    row1 = name1, name2
    row2 = name1, name2
    etc.
    Thanks in advance
    rookey

  2. #2
    Registered User nunomira's Avatar
    Join Date
    May 2002
    Location
    portugal
    Posts
    7,003
    hi,

    Do you want to get rid of ; and , in a string?
    code:

    // the string with ; and ,
    var s = "something; new tha, I may, want;to write";
    // first array without ;
    var a = new Array();
    a = s.split(";");
    // convert to string
    t = a.toString();
    // second array without ,
    var b = new Array();
    b = t.split(",");


  3. #3
    Member
    Join Date
    Nov 2003
    Posts
    50
    nunomira,
    Thanks for your help but it's not that i want to do with my array.
    I would like to remove only "," signs and after all cast in array appear in new row within Combo component, here is one example that is very close to mine solution but please before put one combo on stage and givi it a name pickLetter2_cmb:
    code:
    // arrays
    var names:Array = new Array("Jugo,Gambini", "Jugo,Peter,Andy,Matt,DD", "Peter,Greg,Craig,Thomas", "Peter,Yumin", "Yumin,DD,Dan", "Matt,Yumin", "Matt", "Adam,Adam");
    var myDP:Array = new Array();
    // helper function
    function makeUniqueArray(arrayObj:Array):Array {
    var returnArr:Array = new Array();
    var tempHolder:Object = new Object();
    for (var i = 0; i<arrayObj.length; i++) {
    tempHolder[arrayObj[i]] = arrayObj[i];
    }
    for (key in tempHolder) {
    returnArr.push(tempHolder[key]);
    }
    return returnArr;
    }
    // build our array using values with ","
    for (i=0; i<names.length; i++) {
    var tempArray:Array = new Array();
    tempArray = (names[i].split(","));
    for (j=0; j<tempArray.length; j++) {
    myDP.push(tempArray[j]);
    }
    }
    // sort array
    myDP.sort(1);
    // strip of duplicates
    myDP = makeUniqueArray(myDP);
    // becouse array is reverser reverse it again to get a-z
    myDP.reverse();
    // finnalyy show it
    trace(myDP);
    myDP.unshift("default value");
    pickLetter2_cmb.removeAll();
    pickLetter2_cmb.dataProvider = myDP;
    // select first item by default
    pickLetter2_cmb.selectedIndex = 0;


    but when i put real data from Database instead new array with names it give strange result .... so i thought to simplify this above .... maybe you know for what i'm talking about
    Note: sure that i'm using third part product for database conectivity
    Thanks in advance
    rookey

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