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

Adobe Animate CC code Error

New Here ,
Mar 05, 2018 Mar 05, 2018

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;

}

}

Views

1.4K

Translate

Translate

Report

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

...

Votes

Translate

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

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.

Votes

Translate

Translate

Report

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

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

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

I understand.

Can you share your FLA?

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

Thank You.

That has worked perfectly!

Votes

Translate

Translate

Report

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

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?

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

Hi.

 

Which script are you using?

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

LATEST

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

Votes

Translate

Translate

Report

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