I am currently working on a shooting game, its also a trial for me to use Classes and Packages.
My set up is the stage holds the player, the script then adds 2 movieclips, enemy holder and a bullet holder. The bullet is then added to the bullet holder.
Here is what I have:
package Code{
import flash.display.MovieClip;
import flash.events.*;
public class bullet1 extends MovieClip {
public var core:Object;
public var Bullets:Array = new Array();
private var velocity:Number;
private var speedx:Number;
private var speedy:Number;
public function bullet1(xpos:Number, ypos:Number) {
core=MovieClip(root);
var degreesToRadians:Number = Math.PI/180;
var radiansToDegrees:Number = 180/Math.PI;
var currentRotation:Number;
x = xpos;
y = ypos;
addEventListener(Event.ENTER_FRAME,Tick);
velocity=15;
}
public function Tick(e:Event) {
var degreesToRadians:Number = Math.PI/180;
var radiansToDegrees:Number = 180/Math.PI;
[COLOR=Red] x+=Math.cos((root.player.rotation)*degreesToRadians);
y+=Math.sin((root.player.rotation)*degreesToRadians);[/COLOR]
}
}
}
I am trying to find the rotation of the player who is on the stage from inside my class…
[COLOR=Red] x+=Math.cos((root.player.rotation)*degreesToRadians);
y+=Math.sin((root.player.rotation)*degreesToRadians);
[COLOR=Black]It always gives me:
[/COLOR][/COLOR]
1119: Access of possibly undefined property player through a reference with static type flash.display:DisplayObject.
How can I find the player, or any other instance?