# Function default arguments = null

**URL:** <https://forum.kirupa.com/t/function-default-arguments-null/277051>\
**Category:** Uncategorized\
**Created:** [December 6, 2008, 9:02pm UTC](https://forum.kirupa.com/t/function-default-arguments-null/277051 "2008-12-06T21:02:15Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Xannax](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/xannax/32/3350_2.png) [@Xannax](https://forum.kirupa.com/u/Xannax)\
**Post date:** [December 6, 2008, 9:02pm UTC](https://forum.kirupa.com/t/function-default-arguments-null/277051/1 "2008-12-06T21:02:15Z")

</div>

I’ve been searching for this all over the net to no avail;  
Hope someone points me in the right direction.

Let’s say I have a function like this which purpose is to tween a glow filter:

```auto

public function glow(glowDuration:Number = -1,glowColor:uint=null){

```

I am omitting a lot of stuff from the actual function for the purposes of demonstration.  
Now before you all go “you can’t assign null to a uint”, I know I can’t. Please bear with me until the end of this post.  
Ok, so in the function, I then check for values:

```auto

if(glowDuration!=-1){duration=glowDuration}
if(glowColor!=null){color=glowColor}
//then I go on using the values I need
customTweenEngine.tween("blur",duration,color,blah,blah)

```

“color” is a global variable in my class that can be set either at construction, or after, or in this function.  
I want my tween class to be flexible and so, i want to user to be able to set “color” anytime.  
So the function could be used:

```auto

var fx:FX = new FX(0xFF0000)
fx.glow()
//OR
var fx:FX = new FX()
fx.color = 0xFF0000
fx.glow()
//OR
var fx:FX = new FX()
fx.glow(0xFF0000)
//OR EVEN
var fx:Fx = new FX(0xFF0000)
fx.glow(0x99CCEE)

```

My problem is: You cannot assign null to a uint.  
At the same time, I cannot check for (if glowColor!=0), because the user might want to set it to 0 (black);  
I cannot also just assign glowColor to color without checking, because if the user provided no data, “color” should remain unchanged.

For now, I reverted to:

```auto

public function glow(glowDuration:Number=-1,glowColor:*=null){
if(glowColor!=null)(color = uint(glowColor)

```

Which works, but isn’t satisfying for three reasons:

1. The user can provide any datatype and that ain’t “clean”
2. I will have to have loads of those, and I worry about optimization (flash gurus correct me if I am wrong, but typed data is faster than untyped, right?)
3. My anal instincts itch when I look at “glowColor:\*”. I shouldn’t have to use \*!

And while I am at it, I have the exact same problem with booleans.  
I need to have (glowInner:Boolean = null), because I want to check if the user provided a value (true or false) before changing the global “inner”.  
If i find some answers I’ll post them here.  
If the way I am thinking is utterly stupid please don’t hesitate to point it out.
