The Armor Games website will be down for maintenance on Monday 10/7/2024
starting at 10:00 AM Pacific time. We apologize for the inconvenience.

ForumsProgramming ForumI have a few questions

1 3537
staticzone
offline
staticzone
67 posts
Nomad

HOW DO I - Create an array to store deflector movie clips.
HOW DO I - Create a function that adds a deflector to stage dynamically, and add each deflector to the deflector array.
hopefully you guys can help me out, thank you

  • 1 Reply
beech
offline
beech
107 posts
Nomad

ok - first, can you define what you mean by 'deflector' MCs? i would assume that you are referring to something that creates a 'bounds' like a 'wall' or something?

- to create an array, first you 'declare' it in your code as a 'roperty', as in:

var deflectors:Array = new Array();

- then there are several ways to put things into the array, for instance:

deflectors.push( myDeflector );

OR

deflectors[0] = myDeflector;

- in both cases, 'myDeflector' is an instance of the MC

- now you also can place the instances into the array directly, as in:

var deflectors:Array = [ deflector1, deflector2, ... ];

- in this case, the names in the array must be instances on the stage - in order to place several instances into the array, you can use a FOR loop - say you have a Class instance, with the name 'Deflector' - you can create instances dynamically, like so:

for( var i:int=0; i<10; i++ ) {
var deflector = new Deflector();
deflectors.push( d );
}

- so then you can also add them to the stage using a loop of this type, and assign other properties to them at the same time, something like:

function addDeflectors():void {
for( var i:int=0; i<10; i++ ) {
var deflector = new Deflector();
d.x = 100 * i;
addChild( d );
deflectors.push( d );
}
}

- the above places them on the stage and puts them into the array, it also 'spaces' them at 100pixel increments to the right - but certainly you will want to have more information for placement - but that will entirely depend on what your doing with it

Showing 1-1 of 1