这是我非常简单的代码:
g2.addEventListener(MouseEvent.CLICK, buttG2);
function buttG2(event:MouseEvent):void
{
buttonNote="G2";
addWholeNote();
}
当我单击按钮时效果很好,但是是否可以使用 Actionscript 从另一个函数触发此函数?
这是我非常简单的代码:
g2.addEventListener(MouseEvent.CLICK, buttG2);
function buttG2(event:MouseEvent):void
{
buttonNote="G2";
addWholeNote();
}
当我单击按钮时效果很好,但是是否可以使用 Actionscript 从另一个函数触发此函数?
在其他一些功能中:
function otherFunction() {
buttG2(null);
}
你通过,null
因为它从未被使用过。您还可以给参数一个默认值,如下所示:
function buttG2(event:MouseEvent = null):void
{
buttonNote="G2";
addWholeNote();
}
然后在没有任何参数的情况下调用该函数,因为事件将null
默认为:
function otherFunction() {
buttG2();
}
使用默认参数 null 以允许从代码中的其他位置调用函数。您将无法获得任何 mouseevent 数据,但这可能不是问题。您可以将 null 传递给您的函数,但我发现这更清洁。
g2.addEventListener(MouseEvent.CLICK, buttG2);
function buttG2(event:MouseEvent = null):void
{
buttonNote="G2";
addWholeNote();
}
像任何其他函数一样调用它,参数现在是可选的。
buttG2();