ForumsProgramming Forum(isAlive == false) vs (root == null)

6 10252
weirdlike
offline
weirdlike
1,299 posts
Prince

As you can see by the img below, there are a few class files associated with then main document.

http://i.imgur.com/Bo60LXn.jpg
img link

Without looking at the code, lets assume that every class has listeners. If you removeChild without removing the listeners you get this annoying error message.

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

Two nifty ways of getting rid of this message

addEventListener(Event.ENTER_FRAME, loop);
function loop(event):void
{
if(isAlive == false)
{
removeEventListener(Event.ENTER_FRAME, loop);
//remove other listeners
}
else
{
//loop function
}
}

OR

addEventListener(Event.ENTER_FRAME, loop);
function loop(event):void
{
if(root == null)
{
removeEventListener(Event.ENTER_FRAME, loop);
//remove other listeners
}
else
{
//loop function
}
}

Whats your favorite method?

Is there a different method?

What do you think are the pro's and con's of each method

  • 6 Replies
Showing 166-165 of 6