热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

FlashGameActionscript-3输出错误#1009-FlashGameActionscript-3OutputError#1009

IammakingmyowngameusingActionscript3forcodinginFlash.ThegameisaboutaRunnerCharact

I am making my own game using Actionscript 3 for coding in Flash. The game is about a Runner Character just like Super Mario and Stickyman, who just run, jump, dies.. and so on.. After being very organized by dividing each window of the game in a different Scene, I was still having the problem of executing the piece of code "gotoAndStop()".. That's why I decided to make it much simple by using only one Scene, but each wind of the game in a different frame in the Main Timeline. So I worked on the root, but still getting the same problem that stuck in a white screen!

我正在使用Actionscript 3在Flash中编写自己的游戏。这个游戏讲的是一个Runner角色,就像超级马里奥和Stickyman一样,他只是跑,跳,死...等等。通过在不同的场景中划分游戏的每个窗口非常有条理,我仍然有问题执行一段代码“gotoAndStop()”..这就是为什么我决定通过仅使用一个场景来使其变得简单,但是在主时间轴中的不同帧中的每个风都是如此。所以我在root上工作,但仍然遇到陷入白屏的同样问题!

Anyways, one of the main problem that I am facing here is the Error #1009. Even when I tried to read other topics with the same issue but I didn't find the answer that suites my case.

无论如何,我在这里遇到的主要问题之一是错误#1009。即使我试图用同样的问题阅读其他主题,但我没有找到适合我的案例的答案。

This is the Error:

这是错误:

TypeError: Error #1009: Cannot access a property or method of a null object reference.
    at HR4_fla::MainTimeline/movePlayer()
TypeError: Error #1009: Cannot access a property or method of a null object reference.
    at Apple/update()

Here is the Code:

这是代码:

import flash.events.KeyboardEvent;
import flash.events.Event;
import flash.display.MovieClip;

import flash.geom.Rectangle;
stop();

var KeyThatIsPressed:uint;
var rightKeyIsDown:Boolean = false;
var leftKeyIsDown:Boolean = false;
var upKeyIsDown:Boolean = false;
var downKeyIsDown:Boolean = false;

var score:int = 0;
var lives:int = 3;
player_mc.health = 100;
player_mc.dead = false;
//var TouchRestartBox:Boolean = false;

var playerSpeed:Number = 8;
var gravity:Number = 2;
var yVelocity:Number = 0;
var canJump:Boolean = false;
var canDoubleJump: Boolean = false;

//var appleCount:int;

stage.addEventListener(KeyboardEvent.KEY_DOWN, PressAKey);
stage.addEventListener(KeyboardEvent.KEY_UP, ReleaseAKey);

stage.addEventListener(Event.ENTER_FRAME, cameraFollowCharacter);

function cameraFollowCharacter(event:Event):void
{
 scrollRect = new Rectangle(player_mc.x - stage.stageWidth/2, player_mc.y - stage.stageHeight/2, stage.stageWidth, stage.stageHeight);
}

//PressKey function here
function PressAKey(event:KeyboardEvent):void
{
    if(event.keyCode == Keyboard.RIGHT)
    {
    rightKeyIsDown = true;
    }
    if(event.keyCode == Keyboard.LEFT)
    {
    leftKeyIsDown = true;
    }
    if(event.keyCode == Keyboard.UP)
    {
    upKeyIsDown = true;
    }
    if(event.keyCode == Keyboard.DOWN)
    {
    downKeyIsDown = true;
    }
}

//ReleaseKey function here
function ReleaseAKey(event:KeyboardEvent):void
{
    if(event.keyCode == Keyboard.RIGHT)
    {
    rightKeyIsDown = false;
    }
    if(event.keyCode == Keyboard.LEFT)
    {
    leftKeyIsDown = false;
    }
    if(event.keyCode == Keyboard.UP)
    {
    upKeyIsDown = false;
    }
    if(event.keyCode == Keyboard.DOWN)
    {
    downKeyIsDown = false;
    }
}

//stage.addEventListener(Event.ENTER_FRAME, GameOver);

stage.addEventListener(Event.ENTER_FRAME, movePlayer);

function movePlayer(event:Event):void
{


if(!rightKeyIsDown && !leftKeyIsDown && !upKeyIsDown)
{
    player_mc.gotoAndStop(1);
}       

if(rightKeyIsDown)
{
player_mc.gotoAndStop(2);
player_mc.x+= playerSpeed;
player_mc.scaleX = 0.59;
}

if(leftKeyIsDown)
{
player_mc.gotoAndStop(2);       
player_mc.x-= playerSpeed;
player_mc.scaleX = -0.59;
}

if(upKeyIsDown && canJump)
{
player_mc.gotoAndStop(3);
yVelocity = -15;
canJump = false;
canDoubleJump = true;
}

if(upKeyIsDown && canDoubleJump && yVelocity > -2)
{
    yVelocity = -13;
    canDoubleJump = false;
}

yVelocity +=gravity;

if(!floor_mc.hitTestPoint(player_mc.x,player_mc.y, true))
{
player_mc.y+=yVelocity;
}

if(yVelocity > 20)
{
yVelocity =20;
}

for(var i:int=0; i<10; i++)
{
    if(floor_mc.hitTestPoint(player_mc.x, player_mc.y, true))
    {
    player_mc.y--;
    yVelocity = 0;
    canJump = true;
    }
}

for(var j:int=0; j<=2; j++)
{
    if(rb.hitTestPoint(player_mc.x, player_mc.y, true))
    {
        player_mc.x = -1703.35;
        player_mc.y = 322.1;
        player_mc.scaleX = 0.59;
        lives = lives - 1;
    }

    if(lives == 0)
    {
//          GameOver();
    // remove all the event listeners
//  stage.removeEventListener(Event.ENTER_FRAME, GameOver);
    stage.removeEventListener(Event.ENTER_FRAME, movePlayer);
    stage.removeEventListener(KeyboardEvent.KEY_DOWN, PressAKey);
    stage.removeEventListener(KeyboardEvent.KEY_UP, ReleaseAKey);
    stage.removeEventListener(Event.ENTER_FRAME, cameraFollowCharacter);
gotoAndStop(124);
//(root as MovieClip).gotoAndStop(124);
        }
    }


//  appleCount_txt.text = "Apples:" + appleCount;
}


/*function GameOver()
{
//  lives = 3;


// remove all the event listeners
stage.removeEventListener(Event.ENTER_FRAME, GameOver);
stage.removeEventListener(Event.ENTER_FRAME, movePlayer);
stage.removeEventListener(KeyboardEvent.KEY_DOWN, PressAKey);
stage.removeEventListener(KeyboardEvent.KEY_UP, ReleaseAKey);
stage.removeEventListener(Event.ENTER_FRAME, cameraFollowCharacter);

//  player_mc.stop();
gotoAndStop(1); // this has your "dead" screen on it.
}*/

Can anyone help me solving this problem please? Thanks

有人能帮我解决这个问题吗?谢谢

1 个解决方案

#1


1  

There's a listener still getting executed after the frame change. In that handler, an object is referenced that does not exist on that frame and is thus null. Changing frames only provides visual changes, not necessarily a complete change of state.

在帧更改后,还有一个侦听器仍在执行。在该处理程序中,引用的对象在该帧上不存在,因此为null。改变帧只能提供视觉上的变化,而不一定是完全改变状态。


推荐阅读
author-avatar
Maze-HYW_276
这个家伙很懒,什么也没留下!
Tags | 热门标签
RankList | 热门文章
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有