Actionscript 3 游戏没有';不要在第二帧播放

Actionscript 3 游戏没有';不要在第二帧播放,actionscript-3,flash,Actionscript 3,Flash,我目前正在尝试制作一个游戏,这是一个大学作业。我正在使用flash和ActionScript3来实现这一点(我正在使用一个较旧版本的flash,它是2015年的版本,当时它仍然被称为Adobe flash)。当在第一帧中放置代码时,播放器对象移动效果良好,但是当我将其全部放置在第二帧中时,这不起作用。为什么?代码完全相同!我认为如果我从第2帧开始玩游戏会更方便(至少第一级是在这个帧上)。在第1帧,我想要我的主菜单。下面是我目前在第1帧的代码: import flash.display.Movie

我目前正在尝试制作一个游戏,这是一个大学作业。我正在使用flash和ActionScript3来实现这一点(我正在使用一个较旧版本的flash,它是2015年的版本,当时它仍然被称为Adobe flash)。当在第一帧中放置代码时,播放器对象移动效果良好,但是当我将其全部放置在第二帧中时,这不起作用。为什么?代码完全相同!我认为如果我从第2帧开始玩游戏会更方便(至少第一级是在这个帧上)。在第1帧,我想要我的主菜单。下面是我目前在第1帧的代码:

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

stop();


var optionsActive:Boolean = false;
var gamePaused:Boolean = false;

startGame();

function startGame():void
{
    if (optionsActive == false)
    {
        optionsUI.visible = false;
    }
    else
    {
        optionsUI.visible = true;
    }
    menuTextOptions_active.addEventListener(MouseEvent.CLICK, activateMenuOptions);
    menuTextNewgame_active.addEventListener(MouseEvent.CLICK, activateStartNewGame);

}

function activateStartNewGame(event:Event)
{
    gotoAndStop(2);
}

function activateMenuOptions(event:Event)
{
    optionsActive = true;
    optionsUI.visible = true;
    if (this.currentFrame == 1)
    {
        if (menuTextContinue_active.visible != false)
        {
            menuTextContinue_active.visible = false;
        }
        if (menuTextNewgame_active.visible != false)
        {
            menuTextNewgame_active.visible = false;
        }
        if (menuTextOptions_active.visible != false)
        {
            menuTextOptions_active.visible = false;
        }
        if (menuTextExitgame_active.visible != false)
        {
            menuTextExitgame_active.visible = false;
        }
        if (menuButton_continue.visible != false)
        {
            menuButton_continue.visible = false;
        }
        if (menuButton_newgame.visible != false)
        {
            menuButton_newgame.visible = false;
        }
        if (menuButton_options.visible != false)
        {
            menuButton_options.visible = false;
        }
        if (menuButton_exitgame.visible != false)
        {
            menuButton_exitgame.visible = false;
        }
    }
}
这是我目前在第2帧的代码:

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

stop();

var keybaordLeft:int = 37;
var keyboardUp:int = 38;
var keyboardRight:int = 39;
var keyboardDown:int = 40;

var playerXSpeed:int = 4;
var playerYSpeed:int = 4;

var leftDown:Boolean = false;
var upDown:Boolean = false;
var rightDown:Boolean = false;
var downDown:Boolean = false;

optionsActive = false;
gamePaused = false;

startLevel();

function startLevel():void
{
    if (optionsActive == false)
    {
        optionsUI.visible = false;
    }
    else
    {
        optionsUI.visible = true;
    }
    stage.addEventListener(MouseEvent.CLICK, activateMenuOptions);

    mc_playerShip.addEventListener(Event.ENTER_FRAME, movePlayer);

    stage.addEventListener(KeyboardEvent.KEY_DOWN, checkKeysDown);
    stage.addEventListener(KeyboardEvent.KEY_UP, checkKeysUp);
}

function checkKeysDown(event:KeyboardEvent):void
{
    if (event.keyCode == 37)
    {
        leftDown=true;
    }
    if (event.keyCode == 38)
    {
        upDown=true;
    }
    if (event.keyCode == 39)
    {
        rightDown=true;
    }
    if (event.keyCode == 40)
    {
        downDown=true;
    }
}

function checkKeysUp(event:KeyboardEvent):void
{
    if (event.keyCode == 37)
    {
        leftDown=false;
    }
    if (event.keyCode == 38)
    {
        upDown=false;
    }
    if (event.keyCode == 39)
    {
        rightDown=false;
    }
    if (event.keyCode == 40)
    {
        downDown=false;
    }
}

function movePlayer(event:Event):void
{
    if (leftDown)
    {
        mc_playerShip.x -= playerXSpeed;
    }
    if (upDown)
    {
        mc_playerShip.y -= playerYSpeed;
    }
    if (rightDown)
    {
        mc_playerShip.x += playerXSpeed;
    }
    if (downDown)
    {
        mc_playerShip.y += playerYSpeed;
    }
}

角色根本不动。这是为什么?我如何解决它?

这不是对您问题的回答,但可能仍然有帮助

if (this.currentFrame == 1)
    {
        if (menuTextContinue_active.visible != false)
        {
            menuTextContinue_active.visible = false;
        }
        if (menuTextNewgame_active.visible != false)
        {
            menuTextNewgame_active.visible = false;
        }
        if (menuTextOptions_active.visible != false)
        {
            menuTextOptions_active.visible = false;
        }
        if (menuTextExitgame_active.visible != false)
        {
            menuTextExitgame_active.visible = false;
        }
        if (menuButton_continue.visible != false)
        {
            menuButton_continue.visible = false;
        }
        if (menuButton_newgame.visible != false)
        {
            menuButton_newgame.visible = false;
        }
        if (menuButton_options.visible != false)
        {
            menuButton_options.visible = false;
        }
        if (menuButton_exitgame.visible != false)
        {
            menuButton_exitgame.visible = false;
        }
    }
可以全部替换为以下内容:

If (this.currentFrame == 1){
    if (uiElements.visible != false){
        uiElements.visible = false;
    }
}
如果您只是将所有这些按钮和电影剪辑放入一个名为
uiElements
的父容器中

编辑11-12-16

首先确保导入
flash.display.*

要创建容器,请在任何函数之外执行此操作:

var uiElements:Sprite = new Sprite(); // this creates an instance of the Sprite class 
(精灵与电影剪辑相同,但它没有自己的时间轴,因此占用的内存更少)

然后在主构造函数中执行以下操作:

addChild(uiElements); // this adds the Sprite to the stage
然后,无论您在何处创建要添加到该容器的元素,请执行以下操作:

uiElements.addChild(yourNewMcHere); //this adds your other movie clip to the container
这有意义吗


所以这就是程序化的方法。如果要在IDE中创建元素,只需创建一个空MovieClip并将所有其他MovieClip添加到其中即可(如选择电影剪辑,ctrl+x进行剪切,双击要用作容器的电影剪辑,ctrl+v进行粘贴,对所有要添加到此容器的电影剪辑重复上述操作。这与我演示的以编程方式执行的操作相同)。

这不是对您的问题的回答,但可能仍有帮助

if (this.currentFrame == 1)
    {
        if (menuTextContinue_active.visible != false)
        {
            menuTextContinue_active.visible = false;
        }
        if (menuTextNewgame_active.visible != false)
        {
            menuTextNewgame_active.visible = false;
        }
        if (menuTextOptions_active.visible != false)
        {
            menuTextOptions_active.visible = false;
        }
        if (menuTextExitgame_active.visible != false)
        {
            menuTextExitgame_active.visible = false;
        }
        if (menuButton_continue.visible != false)
        {
            menuButton_continue.visible = false;
        }
        if (menuButton_newgame.visible != false)
        {
            menuButton_newgame.visible = false;
        }
        if (menuButton_options.visible != false)
        {
            menuButton_options.visible = false;
        }
        if (menuButton_exitgame.visible != false)
        {
            menuButton_exitgame.visible = false;
        }
    }
可以全部替换为以下内容:

If (this.currentFrame == 1){
    if (uiElements.visible != false){
        uiElements.visible = false;
    }
}
如果您只是将所有这些按钮和电影剪辑放入一个名为
uiElements
的父容器中

编辑11-12-16

首先确保导入
flash.display.*

要创建容器,请在任何函数之外执行此操作:

var uiElements:Sprite = new Sprite(); // this creates an instance of the Sprite class 
(精灵与电影剪辑相同,但它没有自己的时间轴,因此占用的内存更少)

然后在主构造函数中执行以下操作:

addChild(uiElements); // this adds the Sprite to the stage
然后,无论您在何处创建要添加到该容器的元素,请执行以下操作:

uiElements.addChild(yourNewMcHere); //this adds your other movie clip to the container
这有意义吗


这就是编程的方法。如果你在IDE中创建元素,你只需创建一个空的MovieClip并添加所有其他的MovieClip即可(如选择电影剪辑,ctrl+x进行剪切,双击要用作容器的电影剪辑,ctrl+v进行粘贴,对要添加到此容器的所有电影剪辑重复此操作。这与我演示的以编程方式执行的操作相同).

您的
mc_播放器位于何处
?您在执行后是否有任何错误抛出?或任何运行时错误?它在屏幕上。如果它不在屏幕上,我将无法判断出什么是错误的。当然,它只出现在第二帧中。不,我没有收到任何错误。如果您在中向舞台添加enter frame事件侦听器,该怎么办代替飞船?我不确定这是否会修复它,但我不认为将它添加到飞船中有什么意义。我总是将我的添加到舞台上。根据我的经验,将代码添加到帧中总是会导致意外行为。你的
mc_播放器
位于何处?执行后是否有任何错误抛出?或任何运行时错误?它在屏幕上。我将如果它不在屏幕上,我就无法判断出问题所在。当然,它只出现在第二帧中。不,我没有收到任何错误。如果你将enter frame事件侦听器添加到舞台而不是船上会怎么样?我不确定这是否会解决问题,但我不认为将其添加到船上有什么意义。我总是将我的添加到舞台上。根据我的经验ence,向帧中添加代码总是会导致意外行为。哦,酷。是的,它不会解决我的问题,但肯定会帮助保持代码的一致性。无论如何,我稍微更改了一点;实际上不需要任何检查。我如何创建电影剪辑以及如何将它们全部添加到其中?对不起,我是Flash新手…我没有学过arr是的,这有点道理。谢谢!哦,酷。是的,它不会解决我的问题,但肯定会帮助保持代码的一致性。不管怎样,我稍微更改了一下,实际上不需要任何检查。我如何创建电影剪辑,以及如何将所有剪辑添加到其中?对不起,我是Flash新手……我当时没有学过数组大学。是的,这更有意义。谢谢!