How do you declare a parameter that can be arbitory data type in actionscript 3?

Though this works:

    public function func(settings)

It's reporting a warning,so what's the standard way to do this?


You can use * or Object :

public function foo(bar:*):void{

public function foo(bar:Object):void{

Typing it to "*" or Object datatypes will work - but it's really not ideal. There is probably SOME way to specify a correct datatype.

One answer is to type the input to the most specific common ancestor of all possible inputs - so, for instance, if you know it's going to be a DisplayObject but sometimes it's going to be a Loader and sometimes it's going to be a Sprite, just type it to DisplayObject since both Loader and Sprite ARE technically DisplayObjects.

The other way is perhaps a bit more "correct", and that is to type it to an Interface. Your objects can implement that Interface, and then you're all set.

If you use "*" or Object then you are giving up all ability to debug at that point. Ideally you want to know exactly what objects exist and where they exist in the lifecycle of your application. Every time you cast something as an Object you're giving up - you're saying "And then it goes into this tunnel and disappears", so to speak. It's something best avoided, especially for larger projects that will have to be maintained by other people.

you should definitly specify the return type and parameter classes. this makes your code faster, and much much easier to read in 6 months!

So this would be:

public function saveSettings(settings:Array):void

or what ever might be the appropriate things to call your function :) But don't just call it func.. name it properly :)

Need Your Help

Unexpected line-break with css

css html5 font-face linewrap

On a new project I get some unexpected behavior: When the sidebar is quite small (about 200px) , line breaks occur earlier than needed.

ASP.NET MVC 3 + Serializing a collection displayed into <table>

jquery serialization viewmodel

My ViewModel contains a collection of some object (IEnumerable). The items of the collection are displayed on rows into a tag. When I submit my form, it's triggering submit jQuery function to vali...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.