2012-07-24 55 views
0

我是Flash和Actionscript的新手。我有一個從C#程序啓動的電影。在電影中,我創建了不同的文本字段並將數據傳回給C#程序。我也有一個熱點,當它被點擊時,我想創建一個彈出的小菜單。我已經看了很多方法來做到這一點,我決定最簡單的方法來做到這一點(或者我認爲)會在熱點之下創建幾個按鈕。出於某種原因,當我點擊熱點時,按鈕不會顯示在舞臺上。我知道它正在通過創建按鈕的例程,因爲我顯示一條消息。我發佈了我的代碼。謝謝您的幫助!!Actionscript 3動態創建的按鈕不顯示

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」,但沒有一個按鈕顯示。

加里

+0

運行此代碼時是否收到任何編譯錯誤?我無法找到按鈕as3類的屬性邊框http://livedocs.adobe.com/flash/9.0_es/ActionScriptLangRefV3/fl/controls/Button.html#Button() – danii 2012-07-24 18:30:52

+0

您的項目庫是否包含任何按鈕所需的資產? – 2012-07-25 02:56:52

回答

0
function showMenu(evt: Event):void 

的EVT必須是代替「事件」「的MouseEvent」,因爲你加入到「熱點」精靈(很可能或其它顯示對象)聽者的MouseEvent不是一個事件。

hotSpot.addEventListener(MouseEvent.CLICK, showMenu); 

這調用showMenu函數,該函數偵聽並捕獲MouseEvent而不是Event事件。

您也只導入了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"; 
} 
+0

謝謝你的回覆!我改變了兩條線,他們仍然沒有出現。有趣的是,我在CS5.5中運行了電影並列出了對象(調試菜單)並將其顯示在對象中。只是不在舞臺上。 – Gary 2012-07-24 20:17:07