Highlighted

Adobe Animate CC code Error

New Here ,
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;

}

}

Adobe Community Professional
Correct answer by JoãoCésar | Adobe Community Professional

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

Views

363

Likes

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

Adobe Animate CC code Error

New Here ,
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;

}

}

Adobe Community Professional
Correct answer by JoãoCésar | Adobe Community Professional

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

Views

364

Likes

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
Mar 05, 2018 0
Adobe Community Professional ,
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.

__________________________________________
HTML5, JSFL, and AS3 samples: http://bit.ly/2mJgDoG

Likes

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
Reply
Loading...
Mar 05, 2018 0
New Here ,
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

Likes

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
Reply
Loading...
Mar 05, 2018 0
Adobe Community Professional ,
Mar 05, 2018

Copy link to clipboard

Copied

I understand.

Can you share your FLA?

__________________________________________
HTML5, JSFL, and AS3 samples: http://bit.ly/2mJgDoG

Likes

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
Reply
Loading...
Mar 05, 2018 0
New Here ,
Mar 05, 2018

Copy link to clipboard

Copied

Likes

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
Reply
Loading...
Mar 05, 2018 0
Adobe Community Professional ,
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

__________________________________________
HTML5, JSFL, and AS3 samples: http://bit.ly/2mJgDoG

Likes

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
Reply
Loading...
Mar 05, 2018 1
New Here ,
Mar 05, 2018

Copy link to clipboard

Copied

Thank You.

That has worked perfectly!

Likes

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
Reply
Loading...
Mar 05, 2018 0
Community Beginner ,
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?

Likes

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
Reply
Loading...
Jan 16, 2020 0
Adobe Community Professional ,
Jan 17, 2020

Copy link to clipboard

Copied

Hi.

 

Which script are you using?

__________________________________________
HTML5, JSFL, and AS3 samples: http://bit.ly/2mJgDoG

Likes

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
Reply
Loading...
Jan 17, 2020 0
Community Beginner ,
Jan 19, 2020

Copy link to clipboard

Copied

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

Likes

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
Reply
Loading...
Jan 19, 2020 0
Community Beginner ,
Feb 03, 2020

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

Likes

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
Reply
Loading...
Feb 03, 2020 1