Be a Supporter!

Need AS3 hitTest advice/help!

  • 320 Views
  • 1 Reply
New Topic
Arkuni
Arkuni
  • Member since: Mar. 14, 2005
  • Offline.
Forum Stats
Member
Level 20
Blank Slate
Need AS3 hitTest advice/help! 2009-04-14 02:27:30

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

Afro-Ninja
Afro-Ninja
  • Member since: Mar. 2, 2002
  • Offline.
Forum Stats
Moderator
Level 44
Game Developer
Response to Need AS3 hitTest advice/help! 2009-04-14 02:49:15

flash forum


BBS Signature