Skip to main content
Inspiring
April 25, 2006
Question

array structure

  • April 25, 2006
  • 1 reply
  • 173 views
I'm stillnew to array.
So i'm trying to create a dynamic structure like this:

this_array = new Array();
some_values = new Array();
some_values = param.split ( " , " )
for ( i = 0 ; i < param.length ; i ++ ){
this[ "values_" + i ] = param[ i ] ;
return_values = this[ "values_" + i ]
}
this_array_structure = [ some_object , return_values ]
this_array.push( this_array_structure )
trace ( this_array ) // returns: computer_A , usb

the problem is that the "return_values" consists more than one variable, in this case it has 5 : " dvi , firewire , audio , video , usb "
Somehow it only returns the last variable which is usb.

I'm trying to make it so that it would return something like this:
[ computer_A , dvi , firewire , audio , video , usb ]

The reason why I want to make it dynamic because each item has a different number of properties. In this case computer_A has 5, computer_B may only have 4 and so forth.

Any help would be greatly appreciated.

This topic has been closed for replies.

1 reply

Inspiring
April 25, 2006
The 350Z wrote:

> this_array = new Array();
> some_values = new Array();
> some_values = param.split ( " , " )
> for ( i = 0 ; i < param.length ; i ++ ){
> this = param ;
> return_values = this
> }
> this_array_structure =
> this_array.push( this_array_structure )
> trace ( this_array ) // returns: computer_A , usb


Sorry but your code doesn't make any sense: you are overwritting the this
reference in a for loop and I think you may be confusing the length
property of strings and the length property of arrays, this just cannot
work. Was that a copy paste of the code you are actually using?

Anyway, since you have a string, you don't need a for loop at all, the
method split will return an array directly. So as an example:

var param = "dvi , firewire , audio , video , usb"
var the_array = param.split(" , ");
trace(the_array); // done!

And if you need to add the content of this array to another, check out the
method "concat".

Best luck,
Tim.

The_350ZAuthor
Inspiring
April 25, 2006
Oh the real code.. is hmm maybe too confusing.. but I'll attach it anyway.

-------I also need a suggestions here------------------------------------------------------

So, the whole point is that I'm trying to add some properties to an object.
For example: computer_A would have 5 properties (connectors) which is: usb, dvi, firewire, audio out and video out.
Later I will assign a boolean value to each of these properties.. let's say:

firewire = false;
which mean a firewire connector is closed and not available... or

dvi = true;
which means the dvi connector is still available(open).

I'm open to any suggestions even if I have to start over and leave the array method behind.

Thank you very much