drmcnellis / collisiondetectionkit

Automatically exported from code.google.com/p/collisiondetectionkit
0 stars 0 forks source link

Having a small issue with putting your test code in a Package #3

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Put any of your test codes inside a package (CollisionList or 
CollisionGroup)
and i get:
TypeError: Error #1006: checkCollisions is not a function.
    at Main/checkForCollision()
2.
If i declare the public var collisionGroup=new Array(); as public var 
collisionGroup:*;
I get:
TypeError: Error #1010: A term is undefined and has no properties.
    at Main/checkForCollision() 
so iam thinking that =new Array(); is correctly defined..or is it?
3.

Code is attached hope you can help, iam hoping its me missing something 
small,

BTW I did get it to work fine in timeline, and it's fantastic, used it in 
conjuction with FlintParticles and it detected each Pixel... NICE Hope i 
get it to work inside the package shortly...

What am i missing here?  If anything maybe you can supply a test file 
thats already in a package...

Original issue reported on code.google.com by p...@pkhome.us on 20 Mar 2009 at 6:20

Attachments:

GoogleCodeExporter commented 9 years ago
Yeah, it was just something small you were missing.  The main issue you were 
having 
was properly scoping your variables.

Both your messageBox and collisionGroup variables were being cast as Arrays on 
the 
class level (messageBox is a TextField, and collisionGroup is the class 
CollisionGroup).  Properly casting them fixes part of the problem.

The next issue was that you were declaring collisionGroup inside the 
constructor as 
a local variable (though doing it as CollisionGroup this time).  Here's how the 
compiler sees all of that:

- I have a variable called collisionGroup that's accessible throughout the 
class.  
It's an array.

- I have a variable called collisionGroup that's a CollisionGroup.  It's only 
accessible in the constructor.

So when you run checkCollisions() in your mouse event handler, the only 
collisionGroup varaible it sees is the empty array you declared at the top.  
And 
since checkCollisions() is not a method of Array, you received that error.

Here's an updated version of your file with the necessary corrections.  Runs 
great 
now!  :)

Original comment by lessthan...@gmail.com on 20 Mar 2009 at 2:32

Attachments:

GoogleCodeExporter commented 9 years ago
Ahhh yeah, very good explanation, thank you!  I knew it was those 2 
declarations, 
took a guess with the array...

Thanks for the great code, works perfecty now!

Original comment by p...@pkhome.us on 20 Mar 2009 at 7:47