Topics variables in Actionscript 3.0

In post topics and default variables in Javascript, Actionscript and PHP I was exposed using the techniques of parameter passing and default variables. Add, now, that in ActionScript 3.0 introduces a new parameter declaration can specify an array parameter that accepts any number of arguments separated by commas: ... (rest ... (rest )

1
2
3
4
5
6
7
8
9
10
... mioarr ) : void { sampleFunction function (... mioarr): void {
var i : uint = 0 ; i < mioarr . length ; i ++ ) trace ( mioarr [ i ] ) ; for (var i: uint = 0; i <mioarr. length; i + +) trace (mioarr [i]);
}

, 16 , 32 ) ; sampleFunction (8, 16, 32);

/ / Output:
/ / 8
/ / 16
/ / 32

This technique does not replace the use of the object arguments , but is useful in the class declarations in the absence of parameters where Actionscript generates an error. Furthermore, as mentioned in the manual:

The parameter (rest) can have any name that is not a reserved word and should be the last parameter specified. The use of this parameter makes the object unavailable arguments . Even if the parameter ... (rest) e della proprietà arguments.length , non fornisce invece una funzionalità simile a quella di arguments.callee . ... (rest) offers the same functionality as the arguments and property arguments.length , does not provide functionality similar to that of arguments.callee . Before using the parameter ... (rest) . ... (rest) , make sure you do not need to use arguments.callee .

You can also use this technique together with the declarations are:

1
2
3
4
5
6
7
8
9
a : String , b : int , ... mioarr ) { sampleFunction function (a: String , b: int , ... mioarr) {
var i : uint = 0 ; i < mioarr . length ; i ++ ) trace ( args [ i ] ) ; for (var i: uint = 0; i <mioarr. length; i + +) trace (args [i]);
}

, 16384 , 128 ) ; sampleFunction (4096, 16384, 128);

/ / Output:
/ / 16384
/ / 128

There are no comments for this post

Leave a comment

XHTML TAG PERMIT: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> INSERTION CODE:
 <pre></pre> // blocco generico <code></code> // blocco generico [cc_actionscript][/cc_actionscript] // Actionscript [cc_actionscript3][/cc_actionscript3] // Actionscript 3 [cc_css][/cc_css] // CSS Style Sheet [cc_html][/cc_html] // HTML [cc_js][/cc_js] // Javascript [cc_objc][/cc_objc] // Objective-C [cc_php][/cc_objc] // PHP [cc_sql][/cc_sql] // SQL 


Stop SOPA