2016-04-28 96 views
-1

我正在創建一個Adobe Air Desktop項目,該項目在MainTimeline(RadioSel,CarMC1,CarMC2,CarMC3等)中有許多影片剪輯。 當你點擊任何的CarMC它顯示RadioSel(另一影片剪輯)在函數中將實例名稱作爲字符串傳遞

function showRadio(event: MouseEvent) { 
    RadioSel.visible = true; 
    RadioSel.instance = event.currentTarget.name; 
    trace (RadioSel.instance); 
} 

CarMC是具有多幀的影片剪輯。每個顯示不同的形狀,取決於RadioSel的選擇。 RadioSel是一個具有多個單選按鈕的影片剪輯,每個單選按鈕都將CarMC更改爲不同的形狀,並將名爲instance的變量作爲字符串攜帶單擊的CarMC實例。

我在RadioSel(在radiobuttongroup發生變化時調用)中創建了一個函數,它將點擊的CarMC更改爲指定的幀並隱藏了RadioSel

function chooseCar(CarInstance: String, frame: Number) { 
    this["Object(root)."+CarInstance].gotoAndStop(frame); 
    this.visible = false; 
    //trace(event.target) 
} 

當我改變RadioSel選擇,我把這...

chooseCar(instance, frameNo) 

...其中instanceCarMC的名稱,frameNo是由單選按鈕定義了一些點擊,但是,每次調用該函數時都會出現錯誤。我相信錯誤在這個部分:

this["Object(root)."+CarInstance].gotoAndStop(frame); 

我該如何解決它?

+0

請包括您收到的錯誤。如果您切換「允許調試」並以*調試模式*(https://helpx.adobe.com/animate/using/debugging-actionscript-3-0.html)進行編譯,您可以確切知道發生了什麼行。 – Atriace

回答

0

您沒有傳遞實例(movieclip),而是實例名稱(字符串)。你應該只通過車上實例(動畫片段),使事情變得更容易 - 那麼你不關心你的車,以及如何訪問它們:

function showRadio(event: MouseEvent) 
{ 
    RadioSel.visible = true; 
    // I assume the currentTarget is your car you've clicked on 
    // pass the movieclip instance to the radiosel and not just the name 
    RadioSel.instance = event.currentTarget as MovieClip; 
    trace (RadioSel.instance.name); 
} 

在你RadioSel:

public var instance:MovieClip; 

// no need to pass the instance here as it is saved in the instance property anyway 
function chooseCar(frame: Number) 
{ 
    instance.gotoAndStop(frame); 
    this.visible = false; 
} 
相關問題