Be a Supporter!

Need ActionScript 3 hitTest advice!

  • 330 Views
  • 5 Replies
New Topic Respond to this Topic
Arkuni
Arkuni
  • Member since: Mar. 14, 2005
  • Offline.
Forum Stats
Member
Level 20
Blank Slate
Need ActionScript 3 hitTest advice! 2009-04-14 02:23:25 Reply

I've got a handful of levels, with a character you can control and x amounts of blocks in each level.

I need a good way to hitTest each block without having to write a if case for each and every one of them.

What i got now are 1 player on the scene and 2 blocks named wall_1 and wall_2:

var walls:Array = ['wall_1','wall_2'];
var walls_length:int = walls.length;
for(var i:int = 0; i < walls_length; i++){
if( player.hitTestObject( walls[i] ) ){
trace("you hit: " + walls[i]);
}}

But hitTestObject doesn't take too kindly to array values.
Instead i get an: Error #1034: Type Coercion failed: cannot convert "wall_1" to flash.display.DisplayObject.

Any ideas?


Okay, okay... something funny... something funny.... hmmm.... which quote am I most likely to get away with as my own?... I KNOW!!! "I eat my own shit!" - The local homeless

Arkuni
Arkuni
  • Member since: Mar. 14, 2005
  • Offline.
Forum Stats
Member
Level 20
Blank Slate
Response to Need ActionScript 3 hitTest advice! 2009-04-14 02:25:42 Reply

Sorry guys! Wrong forum!!

It's early and please don't kill me too much for my honest mistake.
I'll just be on my marry way to the right forum.


Okay, okay... something funny... something funny.... hmmm.... which quote am I most likely to get away with as my own?... I KNOW!!! "I eat my own shit!" - The local homeless

Redshift
Redshift
  • Member since: Feb. 12, 2005
  • Offline.
Forum Stats
Member
Level 15
Programmer
Response to Need ActionScript 3 hitTest advice! 2009-04-14 02:50:09 Reply

lol, you must be tired because this is the right forum.


#include <stdio.h>
char*p="#include <stdio.h>%cchar*p=%c%s%c;%cmain() {printf(p,10,34,p,34,10);}";
main() {printf(p,10,34,p,34,10);}

BBS Signature
Redshift
Redshift
  • Member since: Feb. 12, 2005
  • Offline.
Forum Stats
Member
Level 15
Programmer
Response to Need ActionScript 3 hitTest advice! 2009-04-14 03:05:29 Reply

Hm well...

['wall_1','wall_2']

Those are string values. See the problem?


#include <stdio.h>
char*p="#include <stdio.h>%cchar*p=%c%s%c;%cmain() {printf(p,10,34,p,34,10);}";
main() {printf(p,10,34,p,34,10);}

BBS Signature
henke37
henke37
  • Member since: Sep. 10, 2004
  • Offline.
Forum Stats
Member
Level 30
Blank Slate
Response to Need ActionScript 3 hitTest advice! 2009-04-14 06:30:35 Reply

Or if you don't: use real object references and not strings.


Each time someone abuses hittest, God kills a kitten. Please, learn real collision testing.

Arkuni
Arkuni
  • Member since: Mar. 14, 2005
  • Offline.
Forum Stats
Member
Level 20
Blank Slate
Response to Need ActionScript 3 hitTest advice! 2009-04-14 06:36:47 Reply

Nano >

... this is just getting incredible embarrassing.
Time for a power-nap.

Remove the '' and away I go! Thanks a lot!
You are an angel made of tasty melted sugar :)


Okay, okay... something funny... something funny.... hmmm.... which quote am I most likely to get away with as my own?... I KNOW!!! "I eat my own shit!" - The local homeless