# Accessing variable from another class

**URL:** <https://forum.kirupa.com/t/accessing-variable-from-another-class/317830>\
**Category:** flash\
**Created:** [January 4, 2011, 9:52am UTC](https://forum.kirupa.com/t/accessing-variable-from-another-class/317830 "2011-01-04T09:52:31Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![tlhood1080](https://avatars.discourse-cdn.com/v4/letter/t/e19adc/32.png) [@tlhood1080](https://forum.kirupa.com/u/tlhood1080)\
**Post date:** [January 4, 2011, 9:52am UTC](https://forum.kirupa.com/t/accessing-variable-from-another-class/317830/1 "2011-01-04T09:52:31Z")

</div>

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.

```php

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.

![](http://forum.kirupa.com/uploads/kirupa/6427/36b225650397c18e.jpg)
