Copy link to clipboard
Copied
hi , how are you all? i hope you fine...
iam trying to make a game but when the object hit object to delete another object i get these errors
TypeError: Error #2007: Parameter hitTestObject must be non-null.
at flash.display::DisplayObject/_hitTest()
at flash.display::DisplayObject/hitTestObject()
at MAIN/onEnterFrame()
and here is the class
(iam sure the problem from this class because i closed all the classes except 1 )
package {
import flash.display.MovieClip;
import flash.events.Event;
public class MAIN extends MovieClip {
public function MAIN() {
addEventListener(Event.ADDED_TO_STAGE,onAddedToStage)
}
public function onAddedToStage(event:Event):void
{
addEventListener(Event.ENTER_FRAME,onEnterFrame )
}
public function onEnterFrame (event:Event)
{
if (hero.hitTestObject(bat1) && (bat1) && (bat1.stage))
{
healthbar1.width -=1
trace("HHH")
}
if (healthbar1.width >= 80 && healthbar1.width <= 100 ){
zelda1.gotoAndPlay(1)
}
if (healthbar1.width >= 60 && healthbar1.width <= 80){
zelda1.gotoAndPlay(2)
}
if (healthbar1.width >= 40 && healthbar1.width <= 60){
zelda1.gotoAndPlay(3)
}
if (healthbar1.width >= 20 && healthbar1.width <= 40){
zelda1.gotoAndPlay(4)
}
if (healthbar1.width >= 0 && healthbar1.width <= 20){
zelda1.gotoAndPlay(5)
}
if (hero.hitTestObject(portal2)){
var map2:MAP2 = new MAP2
addChild(map2)
if(map1.stage){
removeChild(map1)
}
}
if (hero.hitTestObject(portal3) && (portal3) && (portal3.stage) && (bat1)){var map4:BACKGROUND = new BACKGROUND();
if(bat1){
removeChild(bat1)
bat1.removeEventListener(Event.ENTER_FRAME, onEnterFrame); // this doesn't need to be done unless you added a listener outside the Bat1 classs
bat1 = null;
removeChild(portal3)
portal3 = null
}
}
}
}
}
i talked about this problem before in this discuss
http://forums.adobe.com/message/4620620#4620620
and all the project with the image here
http://forums.adobe.com/message/4615780#4615780
i tried alot to check with if statement the bat1 object but this error still.
thank you
if this thread's problem is resolved, mark helpful/correct responses.
Copy link to clipboard
Copied
you're not following directions. use the code i suggested.
using
if(hero.hitTestObject(bat1)&&bat1)
is NOT the same as
if(bat1){
if(hero.hitTestObject(bat1))
Copy link to clipboard
Copied
i did this
if(bat1){
if(hero.hitTestObject(portal2)){
var map4:BACKGROUND = new BACKGROUND();
removeChild(bat1)
bat1.removeEventListener(Event.ENTER_FRAME, onEnterFrame); // this doesn't need to be done unless you added a listener outside the Bat1 classs
bat1 = null;
removeChild(portal3)
portal3 = null
but you know , after this code this if statement doesn,t work
if(hero.hitTestObject(portal2)){
i dont know why , does the bat become null before that for another reason
thank you
Copy link to clipboard
Copied
ohh sorry, forget that comment i missed somethig there
here
package {
import flash.display.MovieClip;
import flash.events.Event;
public class MAIN extends MovieClip {
public function MAIN() {
addEventListener(Event.ADDED_TO_STAGE,onAddedToStage)
}
public function onAddedToStage(event:Event):void
{
addEventListener(Event.ENTER_FRAME,onEnterFrame )
}
public function onEnterFrame (event:Event)
{
if (bat1){
if (hero.hitTestObject(bat1) )
{
healthbar1.width -=1
trace("HHH")
}
if (healthbar1.width >= 80 && healthbar1.width <= 100 ){
zelda1.gotoAndPlay(1)
}
if (healthbar1.width >= 60 && healthbar1.width <= 80){
zelda1.gotoAndPlay(2)
}
if (healthbar1.width >= 40 && healthbar1.width <= 60){
zelda1.gotoAndPlay(3)
}
if (healthbar1.width >= 20 && healthbar1.width <= 40){
zelda1.gotoAndPlay(4)
}
if (healthbar1.width >= 0 && healthbar1.width <= 20){
zelda1.gotoAndPlay(5)
}
if (hero.hitTestObject(portal2)){
var map2:MAP2 = new MAP2
addChild(map2)
if(map1.stage){
removeChild(map1)
}
}
}
if(hero.hitTestObject(portal3)){
var map4:BACKGROUND = new BACKGROUND();
removeChild(bat1)
bat1.removeEventListener(Event.ENTER_FRAME, onEnterFrame); // this doesn't need to be done unless you added a listener outside the Bat1 classs
bat1 = null;
}
}
}
}
the error still exist
can i give you the fla file , maybe if you take closer look it will be easy to you , if you dont mind?
thank you for your replay
Copy link to clipboard
Copied
use:
package {
import flash.display.MovieClip;
import flash.events.Event;
public class MAIN extends MovieClip {
public function MAIN() {
addEventListener(Event.ADDED_TO_STAGE,onAddedToStage)
}
public function onAddedToStage(event:Event):void
{
addEventListener(Event.ENTER_FRAME,onEnterFrame )
}
public function onEnterFrame (event:Event)
{
if (bat1){
if (hero.hitTestObject(bat1) )
{
healthbar1.width -=1
trace("HHH")
}
if (healthbar1.width >= 80 && healthbar1.width <= 100 ){
zelda1.gotoAndPlay(1)
}
if (healthbar1.width >= 60 && healthbar1.width <= 80){
zelda1.gotoAndPlay(2)
}
if (healthbar1.width >= 40 && healthbar1.width <= 60){
zelda1.gotoAndPlay(3)
}
if (healthbar1.width >= 20 && healthbar1.width <= 40){
zelda1.gotoAndPlay(4)
}
if (healthbar1.width >= 0 && healthbar1.width <= 20){
zelda1.gotoAndPlay(5)
}
}
if (hero.hitTestObject(portal2)){
var map2:MAP2 = new MAP2
addChild(map2)
if(map1.stage){
removeChild(map1)
}
}
if(hero.hitTestObject(portal3)){
var map4:BACKGROUND = new BACKGROUND();
removeChild(bat1)
bat1.removeEventListener(Event.ENTER_FRAME, onEnterFrame); // this doesn't need to be done unless you added a listener outside the Bat1 classs
bat1 = null;
}
}
}
}
the error still exist
can i give you the fla file , maybe if you take closer look it will be easy to you , if you dont mind?
thank you for your replay
Copy link to clipboard
Copied
i copied it then i pasted it , but the problem still the same?
thank you again for your replay
Copy link to clipboard
Copied
then you copied incorrectly.
here's your code properly formatted so you can see the if(bat1) statement do not effect the portal2 hittest:
package {
import flash.display.MovieClip;
import flash.events.Event;
public class MAIN extends MovieClip {
public function MAIN() {
addEventListener(Event.ADDED_TO_STAGE,onAddedToStage);
}
public function onAddedToStage(event:Event):void {
addEventListener(Event.ENTER_FRAME,onEnterFrame);
}
public function onEnterFrame(event:Event) {
if (bat1) {
if (hero.hitTestObject(bat1)) {
healthbar1.width-=1;
trace("HHH");
}
if (healthbar1.width>=80&&healthbar1.width<=100) {
zelda1.gotoAndPlay(1);
}
if (healthbar1.width>=60&&healthbar1.width<=80) {
zelda1.gotoAndPlay(2);
}
if (healthbar1.width>=40&&healthbar1.width<=60) {
zelda1.gotoAndPlay(3);
}
if (healthbar1.width>=20&&healthbar1.width<=40) {
zelda1.gotoAndPlay(4);
}
if (healthbar1.width>=0&&healthbar1.width<=20) {
zelda1.gotoAndPlay(5);
}
}
if (hero.hitTestObject(portal2)) {
var map2:MAP2=new MAP2 ;
addChild(map2);
if (map1.stage) {
removeChild(map1);
}
}
if (hero.hitTestObject(portal3)) {
var map4:BACKGROUND=new BACKGROUND ;
removeChild(bat1);
bat1.removeEventListener(Event.ENTER_FRAME,onEnterFrame);// this doesn't need to be done unless you added a listener outside the Bat1 classs
bat1=null;
}
}
}
}
Copy link to clipboard
Copied
i copied it , but the problem still
sorry mr.kglad
here is the link of the project
http://www.2shared.com/file/fIo-BLEw/project__4__.html
thankyou for your replay
Copy link to clipboard
Copied
ohh , sorry forget that
the problem comes after going to the portal 3
Copy link to clipboard
Copied
if this thread's problem is resolved, mark helpful/correct responses.
Copy link to clipboard
Copied
no the problem still ?!
i sent the link to you
here
http://www.2shared.com/file/fIo-BLEw/project__4__.html
maybe if you take closer look you will know the reason because you are very good in flash , but with me i did all my best but i couldn,t
thank you again for your replay
Copy link to clipboard
Copied
ok , i will try to do that, i mean to fix it alone
thx mr.glad for your help
Copy link to clipboard
Copied
you're welcome.
p.s. someone else might download and correct your file but i generally don't download and correct files unless i'm hired. if you have a question or problem with code, post it in the adobe forums and you'll probably get free help.
Copy link to clipboard
Copied
ohh , ok thx
but i realy have project in my college i should finish it before 3 months
sorry mr.kglad iam not sure if i get this sentence " download and correct files unless i'm hired"
i realy need that person ,help me and explain my errors , so can you help me and i can pay for that if you dont mind?
if you have problem you can just ignore this message
sorry again if i said something wrong
Copy link to clipboard
Copied
ok.
i actually do download and correct files without being hired but only if people offer to pay for my time (like you did). my feeling is, if it's not worth anything to the person with the problem, it's not worth my time.
anyway, i downloaded and checked your file. use:
if (hero.hitTestObject(portal3)) {
var map4:BACKGROUND = new BACKGROUND();
if(bat1){
removeChild(bat1);
bat1.removeEventListener(Event.ENTER_FRAME, onEnterFrame);// this doesn't need to be done unless you added a listener outside the Bat1 classs
bat1=null;
}
}
Copy link to clipboard
Copied
thank you alot mr.kglad.
Copy link to clipboard
Copied
you're welcome.