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