2013-07-07 54 views
0

点击一个按钮,这是我非常简单的代码:AS3:通过ActionScript

g2.addEventListener(MouseEvent.CLICK, buttG2); 
function buttG2(event:MouseEvent):void 
{ 
    buttonNote="G2"; 
    addWholeNote(); 
} 

它,当我点击按钮的伟大工程,但有可能火从使用ActionScript另一个功能这个功能呢?

回答

2

在其他一些功能:

function otherFunction() { 
    buttG2(null); 
} 

您传递null因为它从来没有使用过。你也可以给参数像这样的默认值:

function buttG2(event:MouseEvent = null):void 
{ 
    buttonNote="G2"; 
    addWholeNote(); 
} 

,然后调用函数不带任何参数的事件,然后将null按照默认:

function otherFunction() { 
    buttG2(); 
} 
+0

谢谢你们!我从你们那里得到了同样的答案,选择了第一个,upvoted两个:) – Ryan

1

使用NULL作为默认参数允许从代码中的其他地方调用函数。您将无法获取任何mouseevent数据,但这可能不是问题。你可以像你一样将null传递给你的函数,但是我发现它更干净。

g2.addEventListener(MouseEvent.CLICK, buttG2); 
function buttG2(event:MouseEvent = null):void 
{ 
    buttonNote="G2"; 
    addWholeNote(); 
} 

调用它像其他任何函数一样,param现在是可选的。

buttG2();