# [Problem] AS3 HitTestObject of an Array

Page 1 of 1

## 3 Replies - 12918 Views - Last Post: 29 December 2011 - 05:43 AM

### #1 mXX

Reputation: 0
• Posts: 25
• Joined: 14-April 10

# [Problem] AS3 HitTestObject of an Array

Posted 22 December 2011 - 06:12 AM

Hello,

I'm developing a (first) game in Flash AS3 as my exam for school. I'm still learning the language...

[The concept of the game]
Well I'm trying to make the game "falling blocks" where blocks fall of the sky and you as a player have to climb as high as possible to get as much points.

[What I've got]
I've managed to let blocks fall of the sky on a random x coordination. I've managed to keep the blocks inbound of my stageWidth and the player also stays inbound of the stage width.
I've putted the blocks in an Array. I'm working ObjectOriented ofcourse.

[The problem]
I'm trying to use a HitTestObject for my Arrays of blocks. But this isn't going very well. That's why I'm here...
Before I'm going further with my explaination I'll display the code I'm talking about:

The code in my class Main
```blockTimer = new Timer(1000);
blockTimer.start();

function FallBlocks(evt:TimerEvent):void
{
var blokje:Block = new Block(stage,allBlocks);

//Blokje blijft tussen de randen van de stage
blokje.x = randomNumbers(stage.stageWidth - stage.stageWidth,stage.stageWidth);
allBlocks.push(blokje);

}

```

The code in my class Block
```addEventListener(Event.ENTER_FRAME,update);

function update(evt:Event):void
{
for (var i = 1; i < allBlocks.length; i++)
{
if (hitTestObject(allBlocks[i]))
{
trace("check " + i);

}

```

The output
```check 1
check 1
check 1
Jumping // Happens when I jump with my player so don't mind this
check 1
check 1
check 1
check 1
check 1
check 1
check 1
check 1
check 1
check 1
check 1
check 1
check 1
check 1
check 1
check 1
check 1
check 1
check 2
check 1
check 2
check 1
check 2
check 1
check 2
check 1
check 2
check 1
check 2
check 1
check 2
check 1
check 2
check 1
check 2
check 1
check 2
check 2
check 2
check 2
check 2
check 2
check 2
check 2
check 2
check 2
check 2
check 2
check 2
check 2
check 2
check 2
check 3
check 2
check 3
check 2
check 3
check 2
check 3
check 2
check 3
check 2
check 3
check 3
check 3
check 3
check 3
check 3
check 3
check 3
check 3
check 3
check 3
check 3
check 3
check 3
check 3
check 3
check 3
check 3
check 3
check 3
check 4
check 3
check 4
check 3
check 4
check 3
check 4
check 3
check 4
check 3
check 4
check 4
check 4
check 4
check 4
check 4
check 4
check 4
check 4
check 4
check 4
check 4
check 4
check 4
check 4
check 4
check 4
check 4
check 4
check 4
check 5
check 4
check 5
check 4
check 5
check 4
check 5
check 4
check 5
check 4
check 5
check 5
check 5
check 5
check 5
check 5
check 5
check 5
Jumping
check 5
check 5
check 5
check 5
check 5
check 5
check 5
check 5
check 5
check 5
check 5
check 5
check 6
check 5
check 6
check 5
check 6
check 5
check 6
check 5
check 6
check 1
check 5
check 6
check 6
check 6
check 6
check 6
check 6
check 6
check 6
check 6
check 6
Jumping
check 6
check 6
check 6
check 6
check 6
check 6
check 6
check 6
check 6
check 6
check 7
check 6
check 7
check 6
check 7
check 6
check 7
check 6
check 7
check 6
check 7
check 7
check 7
check 7
check 7
check 7
check 7
check 7
check 7
check 7
check 7
check 7
check 7
check 7
check 7
check 7
check 7
check 7
check 7
check 7
check 8
check 7
check 8
check 7
check 8
check 7
check 8
check 7
check 8
check 1
check 7
check 8
check 8
check 8
check 8
check 8
check 8
check 8
check 8
check 8
check 8
check 8
check 8
check 8

And so on...

```

The problem is that it doesn't actually hit... I've tried to do it without a for loop because it is in an ENTER_FRAME. But then I thought the for loop is for my timer actually. I also asked my teacher, and he also didn't came up with an solution or any tips. That's why I'm tracing the result but I'm not getting any further actually...

Someone can help me in the right direction? Or tell me what I'm doing wrong?

Is This A Good Question/Topic? 0

## Replies To: [Problem] AS3 HitTestObject of an Array

### #2 mXX

Reputation: 0
• Posts: 25
• Joined: 14-April 10

## Re: [Problem] AS3 HitTestObject of an Array

Posted 24 December 2011 - 01:15 PM

Solved...

### #3 RuneChart

Reputation: 2
• Posts: 31
• Joined: 13-July 11

## Re: [Problem] AS3 HitTestObject of an Array

Posted 27 December 2011 - 04:42 AM

I know you said you solved it, but it looks like you're hit testing each block against itself.

```if (hitTestObject(allBlocks[i]) && allBlocks[1]!=this)

{

trace("check " + i);

}

```

### #4 mXX

Reputation: 0
• Posts: 25
• Joined: 14-April 10

## Re: [Problem] AS3 HitTestObject of an Array

Posted 29 December 2011 - 05:43 AM

RuneChart, on 27 December 2011 - 04:42 AM, said:

I know you said you solved it, but it looks like you're hit testing each block against itself.

```if (hitTestObject(allBlocks[i]) && allBlocks[1]!=this)

{

trace("check " + i);

}

```

True this. Thank you!