【发布时间】:2011-05-03 16:41:34
【问题描述】:
好的。情况是这样的……
我有一个自定义的 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';
}
}
谢谢, 杰米
【问题讨论】:
-
只是想解决您的问题。冒泡单击事件并在 Main.mxml 中添加侦听器会解决问题。或者,您可以只发送一个自定义事件来传递您需要的数据吗?
-
Corey,感谢您的回复。请原谅我的无知。我是一个自学成才的新手,还没有学会冒泡。我阅读了 AS3 参考指南,但仍然不完全理解。冒泡是否允许我直接从我的 Main.mxml 引用点击事件?如果是这样,我该如何设置?我的猜测是设置 bubbles = true,然后在 Main.mxml 中放置一个事件监听器?示例代码会有所帮助。谢谢。
标签: flash actionscript-3 flex4 flash-builder flashcatalyst