package { import flash.display.Stage; public class MyGlobal { public static var CX:Number = stage.stageWidth / 2; public static var CY:Number = stage.stageHeight / 2; } }
Error "1120: Access of undefined property stage."WHY?
"1120: Access of undefined property stage."
As already mentioned, stage is a property of classes that inherit from DisplayObject. The stage is not available to the class until it is added to the scene, usually using the addChild method for DisplayObjectContainer.
stage , . DisplayObject, stage . DisplayObject, addChild() .
, , .
DisplayObject, , :
addEventListener(Event.ADDED_TO_STAGE, onAddedToStage);
onAddedToStage() (EDIT: stage , ).
, Object . , , , .
, :
public function Ball(b:Object,stageRef:Object) { ballObject = b; speed = 10; stageRef.addEventListener(KeyboardEvent.KEY_DOWN,function(e:KeyboardEvent):void{ currentKeyCode = e.keyCode; }); stageRef.addEventListener(KeyboardEvent.KEY_UP,function(e:KeyboardEvent):void{ currentKeyCode = 0; }); }
Sam's answer is actually quite right. The easiest way to explain is that it stageis an instance, not a member of a class.
stage
If your fields were not declared static, you can access the scene. But you will probably get a null-reference error;)
Source: https://habr.com/ru/post/1728138/More articles:https://translate.googleusercontent.com/translate_c?depth=1&pto=aue&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=https://fooobar.com/questions/1728133/how-to-handle-authenticated-user-access-to-resources-in-document-oriented-system&usg=ALkJrhguYJrla6oVbK_RkQYpkuODQPVAcAWhat is wrong with this eval statement in Perl? - evalDoes Android launch OpenGL ES 1.1 or 1.0? - androidWhy specify an explicit database connection? - phpHow to use an entity structure at the business level and / or data level? - c #Silverlight: passing a complex object between pages - c #https://translate.googleusercontent.com/translate_c?depth=1&pto=aue&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=https://fooobar.com/questions/1728140/aspnet-passing-arguments-to-the-server-on-button-click&usg=ALkJrhi8Zgoiq-ykxJzpx7royC_lDyb__gBoost Library for RTTI - c ++CSS IE6 float right - htmlHow to change FxCop language? - internationalizationAll Articles