Copy link to clipboard
Copied
Im creating a game using ActionScript 3. I currently have 3 different levels and 2 levels work perfectly fine. However my middle level had a issue where the score of lives would never end and now when the character gets the game over screen. It doesnt allow them to start again. Also im having the Error #1010 on the level.
This is my errors:
TypeError: Error #1010: A term is undefined and has no properties.
at TAOTYS_fla::MainTimeline/frame7()[TAOTYS_fla.MainTimeline::frame7:3]
at flash.display::MovieClip/gotoAndStop()
at TAOTYS_fla::MainTimeline/gameloop4()[TAOTYS_fla.MainTimeline::frame5:19]
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at TAOTYS_fla::MainTimeline/gameloop4()[TAOTYS_fla.MainTimeline::frame5:23]
This is my code:
stop();
var score1 = 0;
score1_txt.text = score1.toString();
var health1 = 3;
health1_txt.text = health1.toString();
stage.addEventListener(Event.ENTER_FRAME, gameloop4);
function gameloop4(e: Event): void {
sword2.x -= 20;
var myNum: Number = Math.random() * 390;
if (sword2.x < -100) {
health1--; //decrease health
sword2.x = 650;
sword2.y = myNum;
health1_txt.text = health1.toString();
if (health1 <= 0) {
stage.removeEventListener(Event.ENTER_FRAME, gameloop4);
stage.removeEventListener(KeyboardEvent.KEY_DOWN, myKeyDown4);
gotoAndStop(1, "end");
}
}
if (man2.hitTestObject(sword2)) {
score1++;
sword2.x = 650;
sword2.y = myNum;
score1_txt.text = score1.toString();
}
}
stage.addEventListener(KeyboardEvent.KEY_DOWN, myKeyDown4);
function myKeyDown4(e: KeyboardEvent): void {
switch (e.keyCode) {
case Keyboard.UP:
man2.y -= 15; //Speed of characters
if (man2.y <= 80) {
man2.y += 15
}
break;
case Keyboard.DOWN:
man2.y += 15;
if (man2.y >= 350) {
man2.y -= 15
}
break;
}
}
Here it is:
Basically, only one score variable has a number in the 'end' scene depending on the difficulty the player chose, but the code tries to access all three score variables, leading to invalid references. What I did was to create a 'level' variable to keep track if the player chose the 'easy', 'medium', or the 'hard' difficulty, so we can check in the end in what level the player was and then assign the correct value to the text field.
Another thing is that when th
...Copy link to clipboard
Copied
Hi.
It's probably because your code tries to access an unavailable instance when you change frames/scenes or when you remove your game loop.
Copy link to clipboard
Copied
I have all the correct instances. My other scenes are the same code as this level, its just this level is having issues
Copy link to clipboard
Copied
I understand.
Can you share your FLA?
Copy link to clipboard
Copied
https://drive.google.com/open?id=1NV9ZlYq64NdtO75l6kWINULcWJYRdDne
This is the whole file
Copy link to clipboard
Copied
Here it is:
Basically, only one score variable has a number in the 'end' scene depending on the difficulty the player chose, but the code tries to access all three score variables, leading to invalid references. What I did was to create a 'level' variable to keep track if the player chose the 'easy', 'medium', or the 'hard' difficulty, so we can check in the end in what level the player was and then assign the correct value to the text field.
Another thing is that when the game loop listener is removed, the associated event handler function still has some code to execute in that tick and then another invalid reference is fired. The solution here is to immediately call a 'return' statement to end the function execution after the gotoAndStop function.
I hope it helps.
Regards,
JC
Copy link to clipboard
Copied
Thank You.
That has worked perfectly!
Copy link to clipboard
Copied
i also have same issue...i already try to add return to may script. but it won't work..can you help me to?
Copy link to clipboard
Copied
Hi.
Which script are you using?
Copy link to clipboard
Copied
Iam using actionscript 3.0...i already try so many think...would you help me
Copy link to clipboard
Copied
thanks for your attention. but my problem is solved. i only go to Modify-->Document then unable Use Advance Layer