O.K.這裏的情況...爲嵌套組件添加功能
我有一個自定義的mxml組件,其中包含幾個圖像和4個按鈕。組件文件已經包含每個按鈕的clickHandler
。我需要能夠訪問clickHandler
或創建另一個功能並將其附加到我的Main.mxml
文件中的這些按鈕。我應該添加到原來的clickHandlers
?如果是這樣,我該如何將該方法應用到我的Main.mxml
文件中?
供參考:組件有5個狀態,每個clickHandler
觸發狀態之間的轉換。
下面是組件文件兩個clickHandlers
:
protected function submit_clickHandler():void
{
const state:String = currentState;
if (state == 'state1') {
currentState='state2';
}
if (state == 'state3') {
currentState='state4';
addElement(images[i]); //The methods I want to run from
getStudentAnswer(); //within the Main.mxml.
submit(); //If I add them here, I get an
newQuestion(); //undefined method error.
}
if (state == 'state4') {
currentState='state4';
}
if (state == 'state5') {
currentState='state4';
}
if (state == 'state3') {
Sequence1.play();
}
}
protected function checkAnswer_clickHandler():void
{
const state:String = currentState;
if (state == 'state2') {
currentState='state1';
}
if (state == 'state4') {
currentState='state5';
}
}
感謝, JM
只是試圖將m你可以迴避你的問題。冒泡點擊事件並在Main.mxml中添加監聽器可以解決問題。或者,您是否可以派遣自定義事件來傳遞您需要的數據? – Corey 2011-05-03 17:30:29
科裏,謝謝你的迴應。原諒我的無知。我是一個自學成才的新手,並沒有學會冒泡。我閱讀AS3參考指南,但仍然不完全明白。 Bubbling是否允許我直接從我的Main.mxml中引用click事件?如果是這樣,我該如何設置它?我的猜測是設置bubbles = true,然後在Main.mxml中放置一個事件監聽器?示例代碼會很有幫助。謝謝。 – 2011-05-03 23:11:26