Note that there are some explanatory texts on larger screens.

plurals
  1. POActionscript 3: How do I access the properties of the document class?
    text
    copied!<p>When I try to access some of the private properties of the document class from another class, it outputs this error:</p> <pre><code>1119: Access of possibly undefined property _player through a reference with static type flash.display:Stage. </code></pre> <p>Here's the code from the document class:</p> <pre><code> package { import flash.display.MovieClip; import flash.events.Event; import flash.events.KeyboardEvent; import flash.utils.Timer; import flash.events.TimerEvent; import flash.ui.Keyboard; import collision; import player; import ground; public class engine extends MovieClip { public var _player:player; private var _ground:ground; private var _collision:collision; private var _right:Boolean; private var _space:Boolean; private var _left:Boolean; private var _touchGround:Boolean; private var _jump:Boolean; private var _jumpVel:int; private var _q:int; private var _vx:int; private var _vy:int; public function engine() { _player = new player(); _ground = new ground(); _collision = new collision(); addChild(_player); addChild(_ground); _player.x = stage.stageWidth/2 - _player.width/2; _player.y = stage.stageHeight/2 - _player.height/2; _ground.x = stage.stageWidth/2 - _ground.width/2; _ground.y = stage.stageHeight/2 - _ground.height/2; _ground.y += 150; _ground.x += 300; _q = 0; stage.addEventListener(Event.ENTER_FRAME, enterFrame); stage.addEventListener(KeyboardEvent.KEY_DOWN,keyDownHandler); stage.addEventListener(KeyboardEvent.KEY_UP,keyUpHandler); } private function enterFrame(e:Event) { if(_right) { if(_vx &gt; 15) { _vx = 15; } _vx += 2; } if(_left) { if(_vx &lt; -15) { _vx = -15; } _vx -= 2; } if(_space &amp;&amp; _touchGround) { _jump = true; } if(_jump) { _jumpVel = 20 - _q; if(_q == 20) { _q = 0; _jumpVel = 0; _jump = false; } else { _ground.y += _jumpVel; _q ++; } } _collision.detectCollisions(); _ground.x -= _vx; _ground.y += _vy; if(_vx &gt; 0) { _vx--; if(_vx &lt; 0) { _vx = 0; } } else if(_vx &lt; 0) { _vx++; if(_vx &gt; 0) { _vx = 0; } } if(_vy &gt; 0) { _vy = 0; } else if(_vy &lt; -10) { _vy = -10; } trace(_vy); } private function keyDownHandler(e:KeyboardEvent) { if(e.keyCode == Keyboard.RIGHT) { _right = true; } if(e.keyCode == Keyboard.LEFT) { _left = true; } if(e.keyCode == Keyboard.SPACE) { _space = true; } } private function keyUpHandler(e:KeyboardEvent) { if(e.keyCode == Keyboard.RIGHT) { _right = false; } if(e.keyCode == Keyboard.LEFT) { _left = false; } if(e.keyCode == Keyboard.SPACE) { _space = false; } } } } </code></pre> <p>Here's the code from the 'collision' class.</p> <pre><code>package { import flash.display.MovieClip; import player; import engine; public class collision extends MovieClip { private var _playerCol:player = engine._player; public function collision() { } public function detectCollisions():void { _playerCol.y += 7; } } } </code></pre> <p>I'm trying to access the property '_player' from the collision class, but am getting an error.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload