Reputation: 199
I'm a beginner to AS3, so sorry if I'm a bit nooby.
I've got two simple objects, Planet and Ship that I want to be gravitationally attracted to each other. When I try to change the x and y coordinates of ship, it gives me error 1119: Access of possibly undefined property x through a reference with static type Class.
The only fixes I have found so far are making sure it's an instance of an object and exporting it for actionscript, both of which have not worked.
Here's the code. The only errors are on the lines that try to access Ship.x and Ship.y:
var yVelocity:Number = 0;
var xVelocity:Number = 0;
var gravityConstant:Number = 1;
var earthMass:Number = 5000;
var canPlay:Boolean = true;
function findDistance():Number {
var distance:Number = Math.pow(Math.pow(Ship.x - 250,2) + Math.pow(Ship.y - 175,2),.5);
return distance;
}
function findAcceleration():Number {
var distance:Number = findDistance();
return gravityConstant * earthMass / Math.pow(distance, 2);
}
function findAngle():Number {
var angle:Number = Math.atan((Ship.y - 175) / (Ship.x - 250));
return (180 / Math.PI) * angle; //converts from radians to degrees
}
function findXAcceleration():Number {
return findAcceleration() * Math.cos(findAngle());
}
function findYAcceleration():Number {
return findAcceleration() * Math.sin(findAngle());
}
function gravity():void {
yVelocity += findYAcceleration();
xVelocity += findXAcceleration();
Ship.x += xVelocity;
Ship.y += yVelocity;
}
do
{
gravity();
} while (canPlay == true);
Upvotes: 0
Views: 5350
Reputation: 345
It looks like you are naming your ship the same name as the class 'Ship' call it something else, _ship for example. At the moment flash thinks when you are typing Ship you are referencing the class and not an instantiated object of it. So..
var _ship:Ship = new Ship();
then use
_ship.x = ...
(providing your Ship Class extends a displayObject)
Upvotes: 1