Results 1 to 3 of 3
-
May 1st, 2012, 07:31 PM #12Registered User
postshitTestObject from within an animated MovieClip help!
Hi, I am having some trouble performing a hit test in a frog game I am making.
When the UP key on the keyboard is pressed an animation in my 'frog' MovieClip plays of a frog jumping, and at frame 22 and 23 (the peak of it's jump) a second nested MovieClip appears for those 2 frames with instance name 'mouth'.
I am trying to hit test mouth against 'fly' which is found on the main timeline.
Here is the code which I can't figure out:
I receive the following error when UP is pressed:Code:stage.addEventListener(KeyboardEvent.KEY_DOWN, frogJump);function frogJump(event:KeyboardEvent) { if(event.keyCode==38) { frog.gotoAndPlay(2); if ((Object(this).frog.mouth).hitTestObject(fly)) {trace("FLY HIT")} } }
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at FrogGame_Game_fla::MainTimeline/frogJump()
Thanks for the help.Last edited by 49th; May 1st, 2012 at 07:34 PM.
-
May 1st, 2012, 08:19 PM #22Registered User
postsTurns out I have solved the problem after over an hour of trying different stuff:
I put the hit test code within the actual movieclip and now it is working.
That feeling when you work something out is great. Even though it was probably the simplest thing!
-
May 2nd, 2012, 02:51 AM #3
That's not really a solution
Especially if your whole project's As is on the first layer. I think it has to do with the this in your hitTest.
As3 / JS/jQuery / HTML5 / CSS(3) / Java(learning) / PHP(learning)
Formerly known as: MJTheOne

Reply With Quote


Bookmarks