Skip navigation
Currently Being Moderated

help me please

Apr 18, 2012 12:53 AM

hi, how are guys

 

first thing i wanna say iam so sorry because iam so useless in this forum  , am just asking without helping 

 

 

here the problem i designed some games and i always get this error 1009 error i.ve read it in this  book (foundation game programming )  and i still cant understand what does he mean

 

here (iam asking in the blue lines and the   problem red lines

help me please it is realy confusing me in game programming)

Adding and removing objects from the stage

Before you look at the code of the game, I need to explain the new way in which classes are being initialized.

Dungeon Maze Adventure has been planned as a multilevel game. If you want to add another

level, it means that you have to remove dungeon one from the stage and add dungeon tow . This gets you

 

into a tricky technical situation regarding how AS3.0 initializes objects in the Flash Player when the

game runs. It’s an extremely important issue to be aware of because it will plague the development of

your Flash games and give you countless sleepless nights if you don’t understand why it happens and

how to solve it.

 

Let’s take a look a look at this problem. When the published SWF of the game runs, it does two things

(in this order):

1. It initializes all the objects by running the constructor methods in their classes.

2. It displays the objects on the stage. (It displays them one by one in the order in which they

were dragged to the stage from the Library when you designed the game in the FLA.)what does he mean by saying display them on the stage?? because i cant see them without addchild method and he said the swf file display them??!!!!!!!!

 

 

 

Here’s the issue: if the class’s constructor method includes a reference to the stage or an object that

is on the stage that hasn’t yet been displayed, you’ll get an error message saying this: here i cant understand any single word!!

Error #1009: Cannot access a property or method of a null object reference.

 

If you’re adding objects to the game, there’s a good chance that many of those objects have to access

the stage as soon as they’re created. They might need to do this to set stage boundaries or access the

properties of other objects that are also on the stage. If they can’t find the stage object because they

haven’t been added to the stage yet, AS3.0’s compiler will “throw its hands in the air” and you’ll see

the preceding error message.

To solve this problem, you need to initialize objects only when they they’ve been added to the stage,

not before.

 

done

 

 

i hope you guys can help me

thank you

 
Replies
  • kglad
    62,117 posts
    Jul 21, 2002
    Currently Being Moderated
    Apr 18, 2012 10:15 AM   in reply to thunderxlight11111

    in the constructor remove the stage reference and move it to init():

     

    function yourconstructor(){

    this.addEventListener(Event.ADDED_TO_STAGE,init);

    }

    private function init(e:Event):void{

    this.removeEventListener(Event.ADDED_TO_STAGE,init);

    // put your stage referencing code here

    }

     
    |
    Mark as:
  • kglad
    62,117 posts
    Jul 21, 2002
    Currently Being Moderated
    Apr 18, 2012 10:34 PM   in reply to thunderxlight11111

    you're welcome.

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points