0

我是 Flash 和 Actionscript 的新手。我有一部电影是从 C# 程序启动的。在电影中,我正在创建不同的文本字段并将数据传递回 C# 程序。我还有一个热点,当它被点击时,我想创建一个弹出的小菜单。我已经研究了很多方法来做到这一点,我决定最简单的方法(或者我认为)是在热点下方创建几个按钮。由于某种原因,当我单击热点时,按钮不会出现在舞台上。我知道它正在执行创建按钮的例程,因为我显示了一条消息。我已经发布了我的代码。谢谢您的帮助!!

import flash.text.TextField;
import fl.controls.Button; 
import flash.events.Event;

hotSpot.addEventListener(MouseEvent.CLICK, showMenu);

var continueBtn:Button;
var exitBtn:Button;

function showMenu(evt: Event):void
{
    continueBtn = new Button();

    continueBtn.x = 20;
    continueBtn.y = 100;
    continueBtn.width = 30;
    continueBtn.height = 20;
    continueBtn.border = true;
    continueBtn.visible = true;
    continueBtn.label = "Continue";
    addChild(continueBtn);

    exitBtn = new Button();

    exitBtn.x = continueBtn.x;
    exitBtn.y = continueBtn.y + continueBtn.height;
    exitBtn.width = 30;
    exitBtn.height = 20; 
    exitBtn.border = true;
    exitBtn.visible = true;
    exitBtn.label = "Exit";
    addChild(exitBtn);

    continueBtn.addEventListener(MouseEvent.CLICK, sendMsg);
    exitBtn.addEventListener(MouseEvent.CLICK, endFlash);

    inTxt.text = "showMenu";

}

显示消息“showMenu”,但没有一个按钮显示。

加里

4

1 回答 1

0
function showMenu(evt: Event):void

evt 必须是“MouseEvent”而不是“Event”,因为您添加到“hotSpot”精灵(可能或其他显示对象)的侦听器是 MouseEvent 而不是 Event。

hotSpot.addEventListener(MouseEvent.CLICK, showMenu);

这将调用 showMenu 函数,该函数侦听并捕获 MouseEvent 而不是 Event 事件。

您还只导入了事件,而是导入了 MouseEvent!新代码:

import flash.text.TextField;
import fl.controls.Button; 
import flash.events.MouseEvent; //This line changed!

hotSpot.addEventListener(MouseEvent.CLICK, showMenu);
var continueBtn:Button;
var exitBtn:Button;
 //This line changed!
function showMenu(evt:MouseEvent):void{
continueBtn = new Button();
continueBtn.x = 20;
continueBtn.y = 100;
continueBtn.width = 30;
continueBtn.height = 20;
continueBtn.border = true;
continueBtn.visible = true;
continueBtn.label = "Continue";
addChild(continueBtn);

exitBtn = new Button();

exitBtn.x = continueBtn.x;
exitBtn.y = continueBtn.y + continueBtn.height;
exitBtn.width = 30;
exitBtn.height = 20; 
exitBtn.border = true;
exitBtn.visible = true;
exitBtn.label = "Exit";
addChild(exitBtn);

continueBtn.addEventListener(MouseEvent.CLICK, sendMsg);
exitBtn.addEventListener(MouseEvent.CLICK, endFlash);

inTxt.text = "showMenu";
}
于 2012-07-24T19:42:10.430 回答