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:
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:
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:
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:
public function glow(glowDuration:Number=-1,glowColor:*=null){
if(glowColor!=null)(color = uint(glowColor)
Which works, but isn’t satisfying for three reasons:
- The user can provide any datatype and that ain’t “clean”
- 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?)
- 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.