Error #1009 after first run

Asked

Viewed 178 times

3

I’m a beginner in AS3, and I’m building a game for a course I’m doing.

As I want the game to be well done, I decided to create a game with menu, where you can access the basic preferences (Turn off music, instructions, etc.)

And when I open the game, and I press the start button, it works normally, as it was programmed, and it doesn’t show any kind of error on the console.

my problem is the game insists on showing me the Error #1009 AFTER THE FIRST EXECUTION!

It is worth noting that when the person loses in the game, he gets two buttons: One allows him a quick restart to the game (back to frame 1 of the scene), and another takes back to the main menu, if the person returns to the game immediately, it works smoothly again. This bug only happens when the person loses, goes back to the menu, and only then plays again!

To understand what was causing the problem, I allowed debugging, and the result:

Saída

I went to check the code on line 2 and realized it’s nothing more than confirmation that the player still has lives:

Código

It is worth mentioning the variable lives on the main Timeline:

Variável lives

I imagine that because it is a test of the value of the variable int, should not be understood as an object by AS3, let alone a null object, but I’m new to AS3, so I’m not sure about that!

EDIT: Following Lucas Nunes' tip, I added:

Código2

Upshot:

Saida2

How should I proceed with this Movieclip(root) when it becomes null??

  • 2

    Was it not the conversion of MovieClip(root) which failed? Check whether MovieClip(root) != null before the rest of controlShield() for us to see...

  • It really was Movieclip(root) that failed! How should I proceed??

1 answer

4


I don’t know exactly how you’re structuring your project, but by the looks of it you’re not using the concept of Flash Objects well.

The ideal is that you define a class that presents the object. For example:

package
{   
    import flash.display.MovieClip;
    import flash.events.Event;
    import flash.events.MouseEvent; 

    public class Caixa extends MovieClip 
    {
        // atributos...
        private var foo:int = 0;

        public function Caixa()
        {
            // seu codigo do contrutor
        }

        public function sumir() : void
        {
            this.visible = false;
        }
    }
}

And in the Flash, associate the MovieClip to that class (when creating one or its properties):

Associando a Classe

After that you can do whatever you want. Let’s assume you have one MovieClip (which is of the Box type) which is called obj_box in the stage, you can do, for example:

inserir a descrição da imagem aqui

import flash.events.MouseEvent;

obj_caixa.addEventListener(MouseEvent.CLICK, destruirCaixa);

function destruirCaixa(e:MouseEvent) : void
{
    obj_caixa.sumir();
}

Or you can define the addEventListener within the class (depending on what you want to do). In this example, what you call MovieClip(root) is that I called it obj_caixa.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.