View Full Version : Multidimentional Object Array
ronnieponnie
02-15-2005, 12:42 PM
I try to make a multidimentional array of sound objects but it doesn´t work. Can someone tell what is wrong about this?
SoundArray = new Array() for(var i = 0; i < 3; i++) { SoundArray[i] = new Array(); for(var j = 0; j < 5; j++) { SoundObject = new Sound(); SoundObject.attachSound("track1-1"); SoundArray[i][j].push(SoundObject); } } SoundArray[2][2].start(0, 1);
Thanks
ronnieponnie
02-15-2005, 12:43 PM
SoundArray = new Array()
for(var i = 0; i < 5; i++) {
SoundArray[i] = new Array();
for(var j = 0; j < 10; j++) {
SoundObject = new Sound();
SoundArray[i][j].push(SoundObject);
}
}
this is the source code properly
Trevor Harrison
02-15-2005, 02:45 PM
SoundArray = new Array()
for(var i = 0; i < 5; i++)
{
SoundArray[i] = new Array();
for(var j = 0; j < 10; j++)
{
SoundObject = new Sound();
SoundArray[i][j].push(SoundObject);
}
}
this is the source code properly
SoundArray = new Array()
for(var i = 0; i < 5; i++)
{
SoundArray.push( new Array() );
var tmp : Array = SoundArray[ SoundArray.length - 1];
for(var j = 0; j < 10; j++)
{
SoundObject = new Sound();
tmp.push(SoundObject);
}
}
ronnieponnie
02-16-2005, 12:55 PM
thanks Trevor Harrison that was the problem :)
Trevor Harrison
02-21-2005, 02:32 PM
I must have been off my feed that day... no need to get the object from the end of the array like I did... this version is slightly better.
SoundArray = new Array();
for(var i = 0; i < 5; i++)
{
var tmp : Array = new Array();
SoundArray.push( tmp );
for(var j = 0; j < 10; j++)
{
SoundObject = new Sound();
tmp.push(SoundObject);
}
}
Raneru
03-03-2005, 02:17 PM
I must have been off my feed that day... no need to get the object from the end of the array like I did... this version is slightly better.
SoundArray = new Array();
for(var i = 0; i < 5; i++)
{
var tmp : Array = new Array();
SoundArray.push( tmp );
for(var j = 0; j < 10; j++)
{
SoundObject = new Sound();
tmp.push(SoundObject);
}
}
But how do you get the Sound object out of the array as a Sound object and not an Object object?
you can not type:
foo:Sound = tmp.pop();
senocular
03-03-2005, 03:19 PM
You just need to know your indexes
foo = SoundArray[firstIndex][secondIndex]
Raneru
03-04-2005, 12:23 PM
Ok. But foo in this example will have to be declared as an Object and not a Sound in order for this to work.
And I want to know how to cast / convert this object from Object to Sound.
if I type this:
var foo:Sound;
var bar:Sound;
foo = new Sound();
array.push(foo);
bar = array.pop(); <---- This produces and error and says that it got Object while expecting Sound
so what I want to do is this:
barbar:Object = array.pop();
bar = (Sound) barbar;
Is there any way to cast an object into another kind of object in actionscript?
|
vBulletin® v3.8.5, Copyright ©2000-2012, Jelsoft Enterprises Ltd.