Forum Topic: mc array as3

(92 views • 4 replies)

This topic is 1 page long.

<< < > >>
Sad

kylelyk

Reply To Post Reply & Quote

Posted at: 7/26/09 10:22 AM

kylelyk LIGHT LEVEL 10

Sign-Up: 05/15/08

Posts: 488

so I have this code. it is supposed to store the references to them in an array.

for (a=1; a<=3; a++) {
	var moun:mountain=new mountain();
	moun.x=mouncur;
	moun.y=253.7;
	moun.name="moun"+a;
	addChild(moun);
	mounarray[(a-1)]=stage.getChildByName("moun"+a);
	trace(mounarray[a])//undefined
}

only, it come out undefined. Help!!

Kylelyk: Forwards and Backwards, Over and Out.

BBS Signature

None

UnknownFury

Reply To Post Reply & Quote

Posted at: 7/26/09 10:34 AM

UnknownFury EVIL LEVEL 26

Sign-Up: 08/10/05

Posts: 6,031

At 7/26/09 10:22 AM, kylelyk wrote: mounarray[(a-1)]=stage.getChildByName("m oun"+a);
trace(mounarray[a])//undefined

only, it come out undefined. Help!!

... You're setting a-1 yet tracing a. Anyway, why bother with all that?

for (a = 0; a <= 3; a++)
{
	mounarray[a] = new mountain();
	mounarray[a].x = mouncur;
	mounarray[a].y = 253.7;
	addChild(mounarray[a]);
	trace(mounarray[a]);
}

Portfolio(Under construction): UnknownFury.com |
Msn: giant_ak_47@msn.com | Contact: me@unknownfury.com
Follow me on twitter!


None

kylelyk

Reply To Post Reply & Quote

Posted at: 7/26/09 10:44 AM

kylelyk LIGHT LEVEL 10

Sign-Up: 05/15/08

Posts: 488

with that code, can I change the "depth" of the array and will it change all the mc's depths inside it? or do I need to make a seperate container mc to do this?

Kylelyk: Forwards and Backwards, Over and Out.

BBS Signature

None

UnknownFury

Reply To Post Reply & Quote

Posted at: 7/26/09 10:54 AM

UnknownFury EVIL LEVEL 26

Sign-Up: 08/10/05

Posts: 6,031

An array doesn't have a 'depth', if you're talking about what I think you are. To change the depth of all of them just put them in a holder MC. So change addChild(mounarray[a]); to myHolder.addChild(mounarray[a]);

Portfolio(Under construction): UnknownFury.com |
Msn: giant_ak_47@msn.com | Contact: me@unknownfury.com
Follow me on twitter!


None

dELtaluca

Reply To Post Reply & Quote

Posted at: 7/26/09 05:36 PM

dELtaluca LIGHT LEVEL 20

Sign-Up: 04/16/04

Posts: 5,542

Right, cba to explain what you're doing wrong, too tired; so i'll show you:

yours:

for (a=1; a<=3; a++) {
var moun:mountain=new mountain();
moun.x=mouncur;
moun.y=253.7;
moun.name="moun"+a;
addChild(moun);
mounarray[(a-1)]=stage.getChildByName("m oun"+a);
trace(mounarray[a])//undefined
}

mine:

var mounarray:Array = new Array(3);
for(var a:uint = 0; a<3; a++)
{
   var moun:mountain = mounarray[a] = new mountain();
   moun.x = mouncur;
   moun.y = 253.7;
   addChild(moun);
}

My social worker says im special!

BBS Signature

All times are Eastern Standard Time (GMT -5) | Current Time: 11:42 PM

<< Back

This topic is 1 page long.

<< < > >>
You need a Grounds Gold Account to post on the NG BBS! If you don't have one, click here to sign up now! It's fast, free, and easy — and opens up tons of great NG features!