I’m having trouble setting up my Ball class so I can set a variable which I can then access in another class later. I’m under the impression you can only do this with a public static var, but when I try to make my variable public static the code doesn’t work.
package {
import flash.display.MovieClip;
import flash.events.Event;
public class Ball extends MovieClip {
public var _startX:uint;
public var _startY:uint;
public var _movingDir:String;
public var _speedR:uint;
public var _speedL:uint;
public var _speedD:uint;
public var _speedU:uint;
public function Ball() {
this.addEventListener(Event.ENTER_FRAME, ballMove);
this.addEventListener(Event.ENTER_FRAME, ballStop);
this._startX = this.x;
this._startY = this.y;
}
public function ballMove(e:Event):void {
if(Start.isStartPressed == true){
if(_startX < 40){
this._movingDir = "right";
_speedR = 5;
this.x += _speedR;
}
else if(_startX > 280){
this._movingDir = "left";
_speedL = 5;
this.x -= _speedL;
}
else if(_startY < 40){
this._movingDir = "down";
_speedD = 5;
this.y += _speedD;
}
else if(_startY > 280){
this._movingDir = "up";
_speedU = 5;
this.y -= _speedU;
}
}
}
public function ballStop(e:Event):void {
if(Start.isStartPressed == false){
this.x = _startX;
this.y = _startY;
}
}
}
}
the code checks where the balls are on the screen and moves them onto the square. I want to set a string variable for the direction its moving eg. “right” for the ball that’s moving right. I’m not sure how to access this in another class. Here is a pic of the screen to visualize.