Passing lots of options to a function I am learning actionscript 3 coding by making a crappy platformer game :)

The problem I am facing is passing lots of options to a construct function that will setup the  display object where all of them have default values.

I could send the options the normal way, like this:

function Box(param1:Number=1, param2:Number=2, param3:Number=3, param4:Number=4){

}


but this seemed to be parameter pollution, so I made this class:

package 
{
    import flash.display.Sprite;
    public class Box extends Sprite {
        public var color:Number = 0x000000;
        public var tileW:Number = 50;
        public var tileH:Number = 50;
        public var walkable:Boolean = true;
        public var speedY:Number = 0;
        public var speedX:Number = 0;
        function Box(options:Object) {
            for(var i:String in options) {
                this[i] = options[i];
            }
            graphics.beginFill(this.color);
            graphics.drawRect(0, 0, this.tileW, this.tileH);
            graphics.endFill();
        }
    }
}


This works, but I have a feeling that I am missing something very basic, that everything I try to write is wrong...
People do this sort of thing all the time in the JavaScript (this.arguments) and Python world (*args); however, by removing type constraints from the parameter list, you have to be wary that you're always providing the types of parameters your function is expecting. If one of your parameters is supposed to be a string, and someone passes in an object, bad things may happen.

Conversely, some very respectable projects use multi-line parameter lists. It's fine to have a lot of parameters, as long as they're all necessary, but it's always good to be skeptical. Long parameter lists is a good code smell – if you see them, the code may need refactoring, but not always.

As far as the attributes of Box's, forget about programming for a second. Conceptually, what are the properties of a box? Can a box still be a box without a color, tileW, tileH, walkable, speedY, and speedX? Can a box still be a box if it doesn't know how to draw itself? If your answer is no to all of these, then your code is fine, and requiring parameters as a single collection/object vs. individual parameters is (arguably) a matter of preference.

That being said, I would move the three graphics.* lines to a separate method Box.draw(). It's best to only do construction in the constructor, and leave the rest – like rendering – to other methods.