AS 3 functions optional value getting error
I have a gui class, The functions optional value getting error. If i am not passing the fillcolor and other optional values.
Error:
ReferenceError: Error #1069: Property fillColor not found on String and there is no default value.
AS 3.0
var windowBase:Sprite = UIClip("Sprite");
/* sliderClip = Gui开发者_StackOverflow.UIClip("MovieClip",{width:100, height:50, fillColor:0xFFFF0D, alpha:.7});
*/
function UIClip (type:String, params:object = '') {
var clip;
trace("Hello")
if (type == 'MovieClip') {
clip = new MovieClip ;
} else {
clip = new Sprite;
}
//trace(params + "params.fillColor " + params.fillColor)
if (params is Object) {
clip.graphics.beginFill ((params.fillColor != "") ? params.fillColor : 0xFFFFFF, params.alpha ? params.alpha : 1 );
clip.graphics.lineStyle (params.lineThickness != "" ? params.lineThickness : 1, params.borderColor ? params.borderColor: 0x000000);
clip.graphics.drawRoundRect (0,0,
(params.width != undefined ) ? params.width : 100,
(params.height != undefined) ? params.height : 100 ,
params.eW ? params.eW : 0,
params.eH ? params.eH : 0);
clip.graphics.endFill ();
//trace("Hello")
}
return clip;
}
How can I solve this?
Condition "if (params is Object)" is true. String is object, too. I'm using null for optional params if they have no default value.
Try this: function UIClip (type:String, params:object = null) and test "if (params != null)"
精彩评论