ActionScript,Flex可选参数,不定参数用法

<?xml version="1.0" encoding="utf-8"?>
<!--
	Description: ActionScript optional and unlimited Arguments Function
	Author: myShareBook.cn
	Create Date: 2009-06-15 
-->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">
	<mx:Script>
		<![CDATA[
			import mx.controls.Alert;
			public function unlimitedArgumentsFunction(var1:int , var2:Object = null , ...vars):void{
				Alert.show('var1 : ' + var1);
				if(null != var2){
					Alert.show('var2 : ' + var2);
				}
				for(var i:int ; i < vars.length ; i++){
					Alert.show('vars ' + i + ' : ' + vars[i]);
				}
			}
		]]>
	</mx:Script>
    <mx:Button label="只传必填参数" click="unlimitedArgumentsFunction(1)" fontSize="12"/>
    <mx:Button label="必填参数 + 可选参数" click="unlimitedArgumentsFunction(1,'I\'m var2')" fontSize="12"/>
    <mx:Button label="必填参数 + 可选参数 + 不定参数" 
    	click="unlimitedArgumentsFunction(1,'I\'m var2',3,['abc','b','c'],8,9)" fontSize="12"/>

</mx:Application>

你可能感兴趣的:(xml,Flex,actionscript)