Home Tutorials Forums Articles Blogs Movies Library Employment Press
Old 05-22-2012, 10:05 PM   #1
bencakir
Registered User
 
Join Date: May 2012
Posts: 5
Default [AS3] Error 1006

I have a guy moving around a maze. Set up pretty well. However, I have one problem

TypeError: Error #1006: hitTestObject is not a function.
at mazegame_fla::MainTimeline/handleCollision()
Here is my code:
ActionScript Code:
import flash.display.MovieClip; import flash.events.Event; stop(); /* Click to Go to Scene and Play Clicking on the specified symbol instance plays the movie from the specified scene and frame. Instructions: 1. Replace "Scene 3" with the name of the scene you would like play. 2. Replace 1 with the frame number you would like the movie to play from in the specified scene. */ return_btn.addEventListener(MouseEvent.CLICK, fl_ClickToGoToScene_6); function fl_ClickToGoToScene_6(event:MouseEvent):void {     MovieClip(this.root).gotoAndPlay(1, "Scene 1"); } stop(); var walls:Array = new Array(wall4_mc,wall5_mc,wall6_mc,wall7_mc,wall8_mc,wall9_mc,wall10_mc,wall11_mc,wall12_mc,wall13_mc,wall14_mc,wall15_mc,wall16_mc); stage.addEventListener(KeyboardEvent.KEY_DOWN, pressKeyDown); function pressKeyDown (e:KeyboardEvent):void{ if (e.keyCode == Keyboard.LEFT){ dude_mc.x -=5; } if (e.keyCode == Keyboard.RIGHT){ dude_mc.x +=5; } if (e.keyCode == Keyboard.UP){ dude_mc.y -=5; } if (e.keyCode == Keyboard.DOWN){ dude_mc.y +=5; } } this.addEventListener(Event.ENTER_FRAME, handleCollision) function handleCollision( e:Event ):void {     if(dude_mc.hitTestObject(hit_mc))        {            gotoAndPlay("1","Scene 6");        }        else if(walls.hitTestObject(dude_mc))        {            gotoAndStop("1","Scene 5");        } }
bencakir is offline   Reply With Quote
Old 05-22-2012, 10:11 PM   #2
bencakir
Registered User
 
Join Date: May 2012
Posts: 5
Default

The swf plays, but this shows in output and guy doesn't go to "x" scene when he hits walls
bencakir is offline   Reply With Quote
Old 05-23-2012, 10:32 AM   #3
Scearezt
Satisfied User
 
Scearezt's Avatar
 
Join Date: Jun 2010
Location: C:\\System32\Hungary
Posts: 426
Lightbulb

You can't checkk collision for arrays, because arrays just stores datas. You can only check collision for instances such as wall1,wall2 etc.. which is currently displayed. So you must run a for cycle to check the collision for each wall in it, and if it hits some of them, then just jump to the scene.

ActionScript Code:
function handleCollision( e:Event ):void {     if(dude_mc.hitTestObject(hit_mc))        {            gotoAndPlay("1","Scene 6");        }        else        {            for(var i:int = 0; i < walls.length; i++){                    if(dude_mc.hitTestObject(walls[i]))                    {                       this.removeEventListener(Event.ENTER_FRAME, handleCollision); //remove event listener (collecting garbage)                       gotoAndStop("1","Scene 5");                       return; //No need for further check so return void.                    }            }        } }

Check these out:
Arrays
Garbage Collection / Memory Management
For Loops
Scearezt is offline   Reply With Quote
Old 05-23-2012, 04:13 PM   #4
bencakir
Registered User
 
Join Date: May 2012
Posts: 5
Default

Quote:
Originally Posted by Scearezt View Post
You can't checkk collision for arrays, because arrays just stores datas. You can only check collision for instances such as wall1,wall2 etc.. which is currently displayed. So you must run a for cycle to check the collision for each wall in it, and if it hits some of them, then just jump to the scene.

ActionScript Code:
function handleCollision( e:Event ):void {     if(dude_mc.hitTestObject(hit_mc))        {            gotoAndPlay("1","Scene 6");        }        else        {            for(var i:int = 0; i < walls.length; i++){                    if(dude_mc.hitTestObject(walls[i]))                    {                       this.removeEventListener(Event.ENTER_FRAME, handleCollision); //remove event listener (collecting garbage)                       gotoAndStop("1","Scene 5");                       return; //No need for further check so return void.                    }            }        } }
When I try your code it still no-clips and returns this:

TypeError: Error #1034: Type Coercion failed: cannot convert wall4_mc$ to flash.display.DisplayObject.
at mazegame_fla::MainTimeline/handleCollision()

wall4_mc is used 52 times in my thingy. Maybe thats the problem?

Last edited by bencakir; 05-23-2012 at 04:16 PM. Reason: Clarity
bencakir is offline   Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 02:28 AM.

///
Follow actionscriptorg on Twitter

 


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.