无法访问空对象引用的属性或方法
我尝试在 Flex 中为我用 Flash 编写的项目进行预加载。 我在这个网站的帮助下做了这个 链接文本 我的 Flash 项目在名为 Game 的主类中有下一个源
stage.addEventListener(KeyboardEvent.KEY_DOWN, keyDown);
stage.addEventListener(KeyboardEvent.KEY_UP, keyUp);
private function keyDown(event:KeyboardEvent) {
if (event.keyCode == 81 && q_was_push == false) q_was_push = true;
if (event.keyCode == 81) press_q = true;
if (event.keyCode == 65) press_a = true;
if (event.keyCode == 83) press_s = true;
if (event.keyCode == 32) press_space = true;
} ...
当我获取由 Flex 制作的新 swf 文件时,出现错误 TypeError:错误#1009:无法访问空对象引用的属性或方法。 在 Game() 中,
如果我评论
//stage.addEventListener(KeyboardEvent.KEY_DOWN, keyDown);
//stage.addEventListener(KeyboardEvent.KEY_UP, keyUp);
Flex 应用程序工作,但 Flash 应用程序对按钮按下没有反应,
请问我如何使预加载器和工作按钮一起工作
I try to do preloder in Flex for my project written in Flash.
I make this with the help of this site
link text
My Flash project have next source in main class called Game
stage.addEventListener(KeyboardEvent.KEY_DOWN, keyDown);
stage.addEventListener(KeyboardEvent.KEY_UP, keyUp);
private function keyDown(event:KeyboardEvent) {
if (event.keyCode == 81 && q_was_push == false) q_was_push = true;
if (event.keyCode == 81) press_q = true;
if (event.keyCode == 65) press_a = true;
if (event.keyCode == 83) press_s = true;
if (event.keyCode == 32) press_space = true;
} ...
When I take new swf file maked by Flex, I have error
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at Game()
if I comment
//stage.addEventListener(KeyboardEvent.KEY_DOWN, keyDown);
//stage.addEventListener(KeyboardEvent.KEY_UP, keyUp);
Flex application work but Flash application does not react to button presses
Please how I can make preloader and work buttons together
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在将显示对象添加到显示列表之前,
stage
属性将为 null。收听 addedToStage 事件并从那里添加主要侦听器。The
stage
property will be null until a display object is added to the display list. Listen to the addedToStage event and add the key listeners from there.每当您需要访问舞台时,请让类在构造函数中侦听/检查它,并让您的 init 函数作为处理程序。
Anytime you need access to the stage, have the Class listen for it/check for it in the constructor, and have your init function be the handler.