Error # 1009 after first run

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 very 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 press the button to start, it works normally, as it was programmed, and does not show any type of error in the console.

My problem is the game insists on showing me Error #1009 AFTER the first run!

It is worth mentioning that when the person loses in the game, it receives two buttons: One allows a quick restart to the game (returning to frame 1 of the scene), and another takes you back to the main menu, if the person returns to the game immediately, it works without problems again. This bug only happens when the person loses, returns to the menu, and then returns to play!

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

Icheckedthecodeonline2andrealizedthatitisnothingmorethanconfirmationthattheplayerstillhaslives:

It's worth highlighting the variable lives in the main timeline:

Ithinkthatsinceitisatestofthevalueofint,itshouldnotbeunderstoodasanobjectbyAS3,letaloneanullobject,butIamnewtoAS3,soI'mnotsure!>

EDIT:FollowingthetipofLucasNunes,Iadded:

Result:

How do I proceed with this MovieClip (root) when it becomes null ??

    
asked by anonymous 17.02.2014 / 02:27

1 answer

4

I do not know exactly how you are designing your project, but it seems you are not using the Flash Object concept well.

Ideally, 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 Flash, associate MovieClip with this class (when you create one or its properties):

Afterthatyoucandowhatyouwant.Let'ssupposeyouhaveaMovieClip(whichisoftypeBox)thatiscalledobj_boxinstage,youcando,forexample:

import flash.events.MouseEvent;

obj_caixa.addEventListener(MouseEvent.CLICK, destruirCaixa);

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

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

    
17.02.2014 / 03:39