dcsimg
A Flash Developer Resource Site

Results 1 to 5 of 5

Thread: [CS3] HELP! How do you list the INDEXES in an Array?

  1. #1
    Special Member Tea_J's Avatar
    Join Date
    Dec 2000
    Posts
    991

    Exclamation [CS3] HELP! How do you list the INDEXES in an Array?

    Lemme be quick with this example...

    say i have the following array constructed inside flash... (multiD array of categories and subcategories)

    subcats_array[8][2]["cid2"] = 2;
    subcats_array[8][2]["subcategory_name"] = "DDR1";

    subcats_array[8][3]["cid2"] = 3;
    subcats_array[8][3]["subcategory_name"] = "DDR2";

    subcats_array[9][4]["cid2"] = 4;
    subcats_array[9][4]["subcategory_name"] = "SATA";

    subcats_array[9][6]["cid2"] = 6;
    subcats_array[9][6]["subcategory_name"] = "IDE";


    I need to list the INDEXES available for subcats_array[9];

    if there was a function for this it'd be Something like..

    trace(subcats_array[9].availableIndexes());

    so result should look like this:

    4,6

    now i know there isnt a function called availableIndexes() for flash, but ya'll get what im trying to achieve here im sure..

    How do i go about this?

    Please help.... im stuck..

  2. #2
    Senior Member
    Join Date
    Aug 2007
    Posts
    291
    When you say available indexes, do you mean which indexes don't have anything in them? Also, your post says CS3, but are you using AS3?

  3. #3
    :
    Join Date
    Dec 2002
    Posts
    3,518

    Maybe you can adapt this to what you are trying to do...

    Code:
    var subcats_array = new Array();
    subcats_array[9] = new Array();
    subcats_array[9][4] = new Array();
    subcats_array[9][4] = [{cid2:4, subcategory_name:"SATA"}];
    subcats_array[9][6] = new Array();
    subcats_array[9][6] = [{cid2:6, subcategory_name:"IDE"}];
    //
    function usedIndexes(arry) {
    	var usedArray = new Array();
    	for (var j = 0; j < arry.length; j++) {
    		if (arry[j] != undefined) {
    			usedArray.push(j);
    		}
    	}
    	return usedArray;
    }
    trace(usedIndexes(subcats_array[9]));

  4. #4
    Special Member Tea_J's Avatar
    Join Date
    Dec 2000
    Posts
    991
    @Tai

    Nope im sticking w/ AS2 .. for the next few years too lolz.. im just so comfy w/ it already.. if this little stumbling block w/ my array is taking me morethan a day to figure out already, God knows how much time i'll lose w/ AS3..


    @dawsonk
    thanks for the input mate..that's looping through the whole array though.. still.. it's a solution.. HOWEVER.. this would work for numbered indexes only.. and wont work with

    var subcats_array = new Array();
    subcats_array[9] = new Array();
    subcats_array[9][4] = new Array();
    subcats_array[9][4] = [{cid2:4, subcategory_name:"SATA"}];
    subcats_array[9][6] = new Array();
    subcats_array[9][6] = [{cid2:6, subcategory_name:"IDE"}];

    subcats_array[10] = new Array();
    subcats_array[10]["asd"] = new Array();
    subcats_array[10]["asd"] = [{cid2:4, subcategory_name:"SATA"}];
    subcats_array[10]["tea"] = new Array();
    subcats_array[10]["tea"] = [{cid2:6, subcategory_name:"IDE"}];


    //
    function usedIndexes(arry) {
    var usedArray = new Array();
    for (var j = 0; j < arry.length; j++) {
    if (arry[j] != undefined) {
    usedArray.push(j);
    }
    }
    return usedArray;
    }
    trace(usedIndexes(subcats_array[10]));
    //returns nothing...


    more suggestions welcome..

    im now experimenting with for(item in array) loop..
    Last edited by Tea_J; 10-22-2008 at 09:04 PM.

  5. #5
    :
    Join Date
    Dec 2002
    Posts
    3,518
    Yes, the 'for in' is what needs to be used.
    Code:
    var subcats_array = new Array();
    subcats_array[9] = new Array();
    subcats_array[9][4] = new Array();
    subcats_array[9][4] = [{cid2:4, subcategory_name:"SATA"}];
    subcats_array[9][6] = new Array();
    subcats_array[9][6] = [{cid2:6, subcategory_name:"IDE"}];
    subcats_array[10] = new Array();
    subcats_array[10]["asd"] = new Array();
    subcats_array[10]["asd"] = [{cid2:4, subcategory_name:"SATA"}];
    subcats_array[10]["tea"] = new Array();
    subcats_array[10]["tea"] = [{cid2:6, subcategory_name:"IDE"}];
    //
    function usedIndexes(arry) {
    	var usedArray = new Array();
    	for (k in arry){
    			usedArray.push(k);
    	}
    	return usedArray;
    }
    trace(usedIndexes(subcats_array[10]));

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