无法访问空对象引用的属性或方法(Cannot access a property or method of a null object reference)

编程入门 行业动态 更新时间:2024-10-23 14:26:12
无法访问空对象引用的属性或方法(Cannot access a property or method of a null object reference)

我尝试在Flash中为我的项目在Flex中执行preloder。 我在这个站点链接文本的帮助下做到这一点我的Flash项目在主类中有下一个源码叫做游戏

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

最满意答案

在将显示对象添加到显示列表之前, stage属性将为空。 收听addedToStage事件并从那里添加关键侦听器。

addEventListener(Event.ADDED_TO_STAGE, onAddedToStage); function onAddedToStage(e:Event):void { stage.addEventListener(KeyboardEvent.KEY_DOWN, keyDown); stage.addEventListener(KeyboardEvent.KEY_UP, keyUp); }

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.

addEventListener(Event.ADDED_TO_STAGE, onAddedToStage); function onAddedToStage(e:Event):void { stage.addEventListener(KeyboardEvent.KEY_DOWN, keyDown); stage.addEventListener(KeyboardEvent.KEY_UP, keyUp); }

更多推荐

本文发布于:2023-07-22 18:26:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1222322.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:属性   无法访问   对象   方法   access

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!