View Full Version : multiple objects with the same instance name
mullwaden
11-30-2003, 12:08 PM
i think its called instance name the extra name an object can have that you use in say getproperty and stuff... anyway:
can i have many objects with the same instancename ? i tried to just give many objects the same but then my hittest thingy wouldn't work (it works if only one object has the same instancename)
the code is something like:
if (gubbe.hitTest(game.walls.left)) {
} else if (Key.isDown(Key.LEFT)) {
this._x -= this.speed;
gubbe._rotation = 180;
}
CyanBlue
11-30-2003, 12:30 PM
Howdy and Welcome... ;)
You cannot have multiple instances with the same instance name... There is no way to get around with that...
As for your hitTest() routine... You can use for loop to do that... Of course you should change the instance names of the objects to be something like gubbe0, gubbe1, gubbe2, gubbe3 and so on...
The example would be something like this...for (i = 0 ; i < 10 ; i++)
{
if (this["gubbe" + i].hitTest(game.walls.left))
{
} else if (Key.isDown(Key.LEFT)) {
this._x -= this.speed;
this["gubbe" + i]._rotation = 180;
}
}
[useastags]
mullwaden
11-30-2003, 01:35 PM
thx allot cyanblue
but it is left i want to change should it be ?
for (i = 0 ; i < 10 ; i++)
{
if (gubbe.hitTest(game.walls.this["left" + i].))
{
} else if (Key.isDown(Key.LEFT)) {
this._x -= this.speed;
this["gubbe" + i]._rotation = 180;
}
}
im such a noob :D
mullwaden
11-30-2003, 01:40 PM
while im at it :D how do i make an action go to a frame in another object... like in this script if i'd like it to go to frame two of "gubbe" when i hit LEFT
CyanBlue
11-30-2003, 02:32 PM
Try this then...for (i = 0 ; i < 10 ; i++)
{
if (gubbe.hitTest(game.walls["left" + i]))
{
} else if (Key.isDown(Key.LEFT)) {
this._x -= this.speed;
gubbe._rotation = 180;
}
}As for your other question, I am not really following what you want to do... :(
mullwaden
11-30-2003, 04:40 PM
ive tried that ... seems that the speed goes berserk when i add a for so my little gubbe moves around 10 times faster than normal :D
question 2: what i want to do is that for example (pseudocode :P)
if(key is down){
goto frame 2 in gubbe
}
CyanBlue
11-30-2003, 05:00 PM
Yup... There is speed issue with the hitTest() with many items, and you cannot get away from it...gubbe.gotoAndPlay(2);
// or
gubbe.gotoAndStop(2);
mullwaden
11-30-2003, 05:48 PM
thx allot its working :) as for the "for script" i did it the boring way:
if (gubbe.hitTest(game.walls.t1)||gubbe.hitTest(game. walls.t2)||gubbe.hitTest(game.walls.t3)||gubbe.hit Test(game.walls.t4)||gubbe.hitTest(game.walls.t5)) {
} else if (Key.isDown(Key.RIGHT)) {
this._x += this.speed;
gubbe.gotoAndStop(2);
}
:D
CyanBlue
11-30-2003, 06:56 PM
Um... I don't supposed that you are to see any speed enhancement with multiple conditions... :confused:
mullwaden
11-30-2003, 07:08 PM
no :) it works so far ... keep your thumbs crossed ;) and thx allot for all the help
jwopitz
05-23-2005, 01:43 AM
Hi Mullwaden and CyanBlue,
I am having an issue with a similar problem. I have multiple instances of a cell dynamically created using:
n = 15;
for (var i = 1; i<n; i++) {
duplicateMovieClip(cell,"cell"+i,i);
}
I have some random movement for the cells. I would like them to move around and if they touch one another they pop. I have this plugged into the MC called cell:
onClipEvent(enterFrame){
//movement code
if (this["cell"+i].hitTest(this["cell"+i])){
trace("hit");
//pop function
}
}
How do I make this so that they can test to see if they are hitting one another?
|
vBulletin® v3.8.4, Copyright ©2000-2009, Jelsoft Enterprises Ltd.