CELEBRATE EARTH WEEK
Save 40% on eBooks and Web Editions*—use code EARTH now through April 27. Shop now.
Publishers of technology books, eBooks, and videos for creative people
Parameters are an essential construct of a method, and the ability to type parameters is of the utmost importance. But what if you are not sure of the value type for a parameter?
In ActionScript 2, the way to avoid this data type dilemma is to type the parameter as an Object or leave it untyped, then Flash will type it as an Object by default.
ActionScript 3 offers a more elegant solution: the wildcard parameter.
The wildcard parameter is simply an asterisk that is used in place of the data type. In the following example, which was used in a blog post earlier this week called Label Statements, the wildcard parameter is used because the data type of the value that is being searched in the containsArtwork method is not known. This solution offers a way to search for a value of any type and see if it exists in the array.
Keep your eyes out for more ActionScript 3 tips like these each day this week.
And for more on ActionScript, be sure to check out my book ActionScript 3.0 Migration Guide, The: Making the Move from ActionScript 2.0.