00:00
00:00
Newgrounds Background Image Theme

novaruah just joined the crew!

We need you on the team, too.

Support Newgrounds and get tons of perks for just $2.99!

Create a Free Account and then..

Become a Supporter!

Need AS3 hitTest advice/help!

517 Views | 1 Reply
New Topic

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

Response to Need AS3 hitTest advice/help! 2009-04-14 02:49:15


flash forum


BBS Signature