flex中的方法,如果参数是不定的,那么可以该函数可以使用不定参数。
我测试的源码如下:
<?xml version=”1.0″ encoding=”utf-8″?>
<mx:Application xmlns:mx=”http://www.adobe.com/2006/mxml” creationComplete=”init()” layout=”absolute”>
<mx:Script>
<![CDATA[
public function init():void
{
b1.addEventListener(MouseEvent.CLICK,a);
b2.addEventListener(MouseEvent.CLICK,a);
}
public function a(event:Event):void
{
if(event.target.id=="b1")
func1(1,"asd"); //这里修改成func来测试不定参数的设置
if(event.target.id=="b2")
func1(2,"wtrerrw");
}
//不定参数的设置
public function func(...args):void
{
for each( var arg:Object in args)
{
if(arg == 1)
trace("1");
else if(arg==2)
trace("2");
else
trace("其他");
}
}
//多个参数的设置
public function func1(a:int=0,b:String ="3"):void{
trace(" a:"+a+" b:"+b);
}
]]>
</mx:Script>
<mx:Button x=”335″ y=”54″ label=”Button1″ id=”b1″/>
<mx:Button x=”335″ y=”121″ label=”Button2″ id=”b2″/>
</mx:Application>
【非商业性转载,请全文转载并署作者名:王海军。商业性使用,请联系作者。欢迎访问我的独立博客http://www.seu528.com】