I have an object on my stage, called obj.
I also have a class called "Physics" which contains a bunch of methods for physics, such as inertia, gravity, and bouncing off walls. In order to do some of these, I need access to the stage.stageWidth and stageHeight properties.
My code is as follows:
public function wallBounce(obj)
{
this.stageRef = stageRef
if (obj.x > stageRef.stageWidth || obj.x < 0)
{
obj.vX = (obj.vX * -1) * bounceConst
}
}
This is supposed to check if the object's x value is greater than the stageWidth or less than 0. When I run this code it says:
TypeError: Error #1009: Cannot access a property or method of a null object reference.
I am a semi-newbie programmer who is completely self-taught and have no clue what is causing this. I spent a bit googling it, and I think it has something to do with scopes, but I don't know how to fix this, and barely even know what scopes really do.
Again, sorry if this a really stupid question, but I just can't figure out what I'm doing wrong.