【问题标题】:ActionScript 3.0: Moving to another scene by clicking a buttonActionScript 3.0:通过单击按钮移动到另一个场景
【发布时间】:2017-03-09 10:00:18
【问题描述】:

我已经创建了我的小项目的第一个场景。现在我想转到应用程序的第二个场景。第一个称为 startScene,第二个称为 playScene。下面是链接到第一个场景的类的代码:

package {
import flash.display.MovieClip;
import flash.display.Sprite;
import flash.text.TextField;
import flash.text.TextFormat;
import flash.text.TextFieldAutoSize;
import flash.events.MouseEvent;



public class dragMain extends MovieClip {


    public function dragMain() {
        setWelcomeMessage();
        drawArrow();
        createStartButton();
    }
    // funzione per settare il messaggio di benvenuto
    function setWelcomeMessage(): void {
        // TextField contenete il messaggio di benvenuto
        var welcomeMessage: TextField = new TextField();
        // formattazione per il messaggio di benvenuto
        var welcomeFormat: TextFormat = new TextFormat("Verdana", 40, 0xFF0000);
        // imposto il testo da visualizzare
        welcomeMessage.text = "Welcome, click the button to start playing";
        // 
        welcomeMessage.autoSize = TextFieldAutoSize.LEFT;
        // cerco di centrare il testo ad occhio nella schermata         
        welcomeMessage.x = 500;
        // applico la formattazione al testo
        welcomeMessage.setTextFormat(welcomeFormat);
        // aggiungo il testo allo stage         
        addChild(welcomeMessage);
    }
    // funzione che disegnera' la freccia
    function drawArrow(): void {

        // Sprite che conterra' la freccia disegnata
        var arrow: Sprite = new Sprite();

        arrow.graphics.beginFill(0XFF0000);
        arrow.graphics.moveTo(800, 100); //500,500 // 200,200
        arrow.graphics.lineTo(1000, 100); //700,500 // 400,200
        arrow.graphics.lineTo(1000, 550); //700,950 // 400,650
        arrow.graphics.lineTo(1100, 550); //800,950 // 500,650
        arrow.graphics.lineTo(900, 700); //600,1100// 300,800
        arrow.graphics.lineTo(700, 550); //400,950 // 100,650
        arrow.graphics.lineTo(800, 550); //500,950 // 200,650
        arrow.graphics.lineTo(800, 100); //500,500 // 200,200
        addChild(arrow);
    }

    // funzione per creare il bottone
    function createStartButton(): void {
        var button: Sprite = new Sprite();

        button.graphics.beginFill(0xFF0000);
        button.graphics.moveTo(700, 800);
        button.graphics.lineTo(1100, 800);
        button.graphics.lineTo(1100, 1000);
        button.graphics.lineTo(700, 1000);
        button.graphics.lineTo(700, 800);
        var clickMeMessage: TextField = new TextField();
        clickMeMessage.x = 855;
        clickMeMessage.y = 865;
        var welcomeFormat: TextFormat = new TextFormat("Verdana", 40, 0x000000);
        // imposto il testo da visualizzare
        clickMeMessage.text = "click me!";
        // 
        clickMeMessage.autoSize = TextFieldAutoSize.CENTER;
        // applico la formattazione al testo
        clickMeMessage.setTextFormat(welcomeFormat);

        addChild(button);
        addChild(clickMeMessage);

        button.addEventListener(MouseEvent.CLICK, onClick);

    }
    function onClick(evt: MouseEvent): void {
        gotoAndPlay(1, "playWindow");
    }
}

}

当我单击通过代码创建的按钮时,我总是在 startScene 上,无法移动到 playScene。我在 startScene 上有一个框架,在 playScene 上有一个框架。有什么问题,我该如何解决?谢谢!

【问题讨论】:

  • 你的代码说的是“playWindow”,而不是“playScene”。
  • 谢谢你,我的错误!我纠正了它,但仍然没有发生。太奇怪了!你知道吗?
  • 这是根脚本吗?我的意思是,它在主时间线上?
  • 不。我创建了一个名为 dragMain.as 的文件(我在其中放置了所有这些代码),并将它与文件 drag.fla 相关联
  • 让我换个说法。这段代码是主文档类吗?

标签: actionscript-3 button frame scene


【解决方案1】:

首先要做的事情。

你已经完成了 gotoAndPlay,所以它将在第 1 帧的所有场景之间不断迭代

gotoAndStop(1,"playScene");

如果您不想要在开始场景中添加的所有东西,您应该删除它们或将它们的可见性设置为 false,因为 addchild 会将对象添加到舞台

这就是我所做的。我将以下变量设为全局

var welcomeMessage: TextField;
var button: Sprite;
var clickMeMessage: TextField;
var arrow: Sprite; 

并稍微修改了 onclick 函数

function onClick(evt: MouseEvent): void {
        button.visible = false;
        clickMeMessage.visible = false;
        arrow.visible = false;
        welcomeMessage.visible = false;
        gotoAndStop(1, "playScene");

    }

我认为这应该可行

【讨论】:

    【解决方案2】:

    试试 gotoAndStop(1, "playWindow");而不是 gotoAndPlay()。我怀疑您在 playScene 的第 1 帧上没有 stop() ,因此 Flash 继续经过该场景。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-09-07
      • 2018-09-07
      • 2013-04-13
      • 1970-01-01
      • 1970-01-01
      • 2016-03-22
      • 2015-03-13
      • 2020-04-01
      相关资源
      最近更新 更多