var arr:Array = new Array( {food:'Hamburger', soda:'Rootbeer'}, {food:'Pizza', soda:'7up'} ); trace(arr.indexOf(food:'Hamburger')); ?? I know that doesn't work, but is there syntax to make it work, or does one have to write their own class to handle this?
I wonder if performance wise, it'd be better to use a multidimensional array? var arr1:Array = new Array('Hamburger', 'Pizza'); var arr2:Array = new Array('Rootbeer', '7up'); var arr3:Array = new Array(arr1, arr2); var index = arr3[0].indexOf('Hamburger'); var soda = arr3[1][index]; lol
in your first message arr is an array of objects (that each have two properties). indexOf will search for array elements that match the parameter used. in your case, that parameter would be an object, not an object property and value. you could write another function that returns the object(s) that match a particular property/value and use that in the indexOf parameter. your 2nd message contains a different construct for arr3. no longer do you have objects with a food and soda property. you have an array with foods and sodas and the foods and sodas have no relationship to each other.
That's what I understood. Would your function be a set of loops that finds the passed parameter value? function(prop):Object for(var i in AssocArray) { for (var j in AssocArray[i]) { if(AssocArray[i][j]==prop) { return AssocArray[i][j]; } } }
: function findArrayIndex(prop,value,arr){ // pass prop as a string for(var i=0;i<arr.length;i++){ if(arr[i][prop]== value){ return i; // returns first matching index }
gotoAndPlay() and stop() i've been using since flash 4. i started to move beyond novice in 2002. and i think i've been pretty capable since 2004. and at this point, i feel confident that if something can be done with actionscript, i can do it.
Never been asked to design a 3d bus?? hehe http://theflashblog.com/ My experience with p3d is that it's very neat what you can do, but it's costly on the renderer, so you better not have much else going on at the same time...
It's brutiful !!!! [code] var arr:Array = new Array( {name:'myArray', fish:'Beta', cheese:'guda'}, {name:'yourArray', fish:'Trigger', cheese:'Cheddar'} ); function findArrayIndex(prop,value,arr):int { // pass prop as a string for(var i=0;i<arr.length;i++) { if(arr[i][prop]== value) { return i; // returns first matching index } } return undefined; } trace( arr[findArrayIndex('name', 'yourArray', arr)].fish ); [/code]
Don't see what you're looking for? Try a search.
|