1 Replies - 1621 Views - Last Post: 16 May 2012 - 10:52 PM

#1 Gamegoofs2  Icon User is offline

  • D.I.C Head

Reputation: 5
  • View blog
  • Posts: 159
  • Joined: 15-April 09

Adding a Stage Event from another class

Posted 09 May 2012 - 02:55 PM

I'm trying to add an ENTER_FRAME event to the stage from another class, but whenever I created a new instance of I get "TypeError: Error #1009: Cannot access a property or method of a null object reference." However if I drop an instance of the object directly onto the stage it works fine.

Here's my code:

public class Food extends MovieClip {
  public function Food() {
     stage.addEventListener(Event.ENTER_FRAME, foodFall);
  }
}



Is This A Good Question/Topic? 0
  • +

Replies To: Adding a Stage Event from another class

#2 lazh  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 16-May 12

Re: Adding a Stage Event from another class

Posted 16 May 2012 - 10:52 PM

hi have you tried putting on the class name then the function you want too call from other classes

something like this:
public class Food extends MovieClip {
  public function Food() {
     stage.addEventListener(Event.ENTER_FRAME, ClassNameWhereFoodFallbelongs.foodFall);
  }
}



ClassNameWhereFoodFallbelongs is the class where foodFall function is located.

btw you might also need to import the class name of the class you want to use.

Hope this helps.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1