Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Adobe Animate CC code Error

New Here ,
Mar 05, 2018 Mar 05, 2018

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;

}

}

2.3K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Mar 05, 2018 Mar 05, 2018

Here it is:

TAOTYS.fla - Google Drive

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

...
Translate
Community Expert ,
Mar 05, 2018 Mar 05, 2018

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Mar 05, 2018 Mar 05, 2018

I have all the correct instances. My other scenes are the same code as this level, its just this level is having issues

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 05, 2018 Mar 05, 2018

I understand.

Can you share your FLA?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Mar 05, 2018 Mar 05, 2018
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 05, 2018 Mar 05, 2018

Here it is:

TAOTYS.fla - Google Drive

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Mar 05, 2018 Mar 05, 2018

Thank You.

That has worked perfectly!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jan 16, 2020 Jan 16, 2020

i also have same issue...i already try to add return to may script. but it won't work..can you help me to?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 17, 2020 Jan 17, 2020

Hi.

 

Which script are you using?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jan 19, 2020 Jan 19, 2020

Iam using actionscript 3.0...i already try so many think...would you help me

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Feb 03, 2020 Feb 03, 2020
LATEST

thanks for your attention. but my problem is solved. i only go to Modify-->Document then unable Use Advance Layer

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines