2012-08-08 82 views
0

我開始使用Flash CS6首次嘗試做的Scaleform UI對UDK。我正在遵循這個簡單的教程:http://goo.gl/yedMU。我已經把它寫到了這封信上,但似乎無法讓它工作。我甚至在一個新的項目中再次嘗試過,但最後卻出現了同樣的錯誤。我三重檢查了每個名稱和實例,但它拒絕工作。下面是兩個框架的文件中的非常簡單的代碼:的Flash CS6錯誤#1009 - 巴頓消失

import flash.events.MouseEvent; 
import flash.system.fscommand; 
import flash.display.MovieClip; 

subMenu_btn.addEventListener(MouseEvent.CLICK, subMenu); 
exit_btn.addEventListener(MouseEvent.CLICK, exitGame); 

var cursor:cursor_mc = new cursor_mc(); 
addChild(cursor); 
    cursor.x = mouseX; 
    cursor.y = mouseY; 
cursor.startDrag(); 

stop(); 

function subMenu(event:MouseEvent):void 
{ 
    gotoAndStop('Sub Menu'); 
} 
function exitGame(event:MouseEvent):void 
{ 
    fscommand('ExitGame'); 
} 

play_btn.addEventListener(MouseEvent.CLICK, playGame); 
back_btn.addEventListener(MouseEvent.CLICK, backBtn); 

function playGame(event:MouseEvent):void 
{ 
    fscommand('PlayMap'); 
} 
function backBtn(event:MouseEvent):void 
{ 
    gotoAndStop('Main Menu'); 
} 

我使用的調試和

exit_btn.addEventListener(MouseEvent.CLICK, exitGame); 

任何想法的代碼休息?整個事情的工作,直到我用'返回'按鈕返回到第一幀,當'退出'按鈕消失,我得到這個錯誤。然而,'子菜單'按鈕仍然可用,菜單仍可操作。

這是使用調試器中的錯誤:

TypeError: Error #1009: Cannot access a property or method of a null object reference. 
at Menu_fla::MainTimeline/frame1()[Menu_fla.MainTimeline::frame1:6] 
at flash.display::MovieClip/gotoAndStop() 
at Menu_fla::MainTimeline/backBtn()[Menu_fla.MainTimeline::frame2:10] 
+0

是否有「主菜單」框上的「exit_btn」?你正在告訴Flash聽一些不在那裏的東西。右側有一個邊欄,裏邊有很多與你有同樣問題的人,你可能想要查看。 – Duke 2012-08-08 01:46:34

+0

我瀏覽過這些帖子中的每一個,但沒有找到答案。這裏是該項目,所以你可以看到它:http://www.sendspace.com/file/f8y82w – Taslem 2012-08-08 01:54:01

+0

我相信正在發生的事情是Flash每次你改變一個幀都會將所有的影片剪輯「零」你可以看到這個,如果你調試並看看這個 - > exit_btn(它的值爲空)。我會在答案部分發表我的建議。 – Duke 2012-08-08 02:39:04

回答

0

好了,所以我在上面的評論說,我可能是錯的,解決的辦法是這樣的:

爲了您的第一幀的AS3:

import flash.events.MouseEvent; 
import flash.system.fscommand; 
import flash.display.MovieClip; 

var cursor:cursor_mc = new cursor_mc(); 

subMenu_btn.addEventListener(MouseEvent.CLICK, subMenu); 
exit_btn.addEventListener(MouseEvent.CLICK, exitGame); 

addChild(cursor); 
    cursor.x = mouseX; 
    cursor.y = mouseY; 
cursor.startDrag(); 
Mouse.hide(); 

stop(); 

function subMenu(event:MouseEvent):void 
{ 
    subMenu_btn.removeEventListener(MouseEvent.CLICK, subMenu); 
    exit_btn.removeEventListener(MouseEvent.CLICK, exitGame); 
    removeChild(cursor); 
    gotoAndStop('Sub Menu'); 
} 
function exitGame(event:MouseEvent):void 
{ 
    fscommand('ExitGame'); 
} 

關於你的第二幀的AS3:

play_btn.addEventListener(MouseEvent.CLICK, playGame); 
back_btn.addEventListener(MouseEvent.CLICK, backBtn); 

cursor = new cursor_mc(); 
addChild(cursor); 
    cursor.x = mouseX; 
    cursor.y = mouseY; 
cursor.startDrag(); 
Mouse.hide(); 

function playGame(event:MouseEvent):void 
{ 
    fscommand('PlayMap'); 
} 
function backBtn(event:MouseEvent):void 
{ 
    removeChild(cursor); 
    gotoAndStop('Main Menu'); 
} 

你每次碰到幀1時都會實例化遊標,我相信會造成命名空間問題。解決方法是從舞臺上移除光標,並將其添加回每幀。可能有一個更優雅的解決方案,但因爲我從來沒有使用AS的多個幀(出於這個原因),這是我能做的最好的。我還隱藏了鼠標光標,讓您的cursor_mc更加專注。

讓我知道,如果您有任何其他問題。 快樂編碼!

+0

謝謝!有趣的是我嘗試了UDK中的swf,它運行良好,至少可以說是怪異的。雖然很好的答案。 – Taslem 2012-08-08 12:44:37

+0

很高興幫助,@Taslem!如果確實解決了問題,請將我的解決方案標記爲答案。謝謝你,快樂的編碼! – Duke 2012-08-09 04:28:57

0

另一解決方案是創建一個新的層,並且把光標代碼僅在該層上。該圖層將具有一個關鍵幀,並延伸至覆蓋整個時間線,因此它始終處於活動狀態。

或者,創建於框架1.這影片剪輯中存在menu影片剪輯,你有不同的幀的菜單的各個部分(選項等)。光標將與菜單影片剪輯存在於同一級別。所以它總是存在並且只被初始化一次。