Reading component parameters and setting defaults
Posted
by donut
on Stack Overflow
See other posts from Stack Overflow
or by donut
Published on 2010-04-13T02:38:40Z
Indexed on
2010/04/13
2:42 UTC
Read the original article
Hit count: 433
I'm pulling my hair on this because it should be simple, but can't get it to do the right thing. What's the best practice way of doing the following
I've created a custom component that extends <s:Label>
so now the Label has additional properties color2
color3
value
which can be called like this and are used in the skin.
<s:CustomLabel text="Some text"
color2="0x939202"
color3="0x999999"
value="4.5" />
If I don't supply these parameters, I'd like some defaults to be set. So far I've had some success, but it doesn't work 100% of the time, which leads me to think that I'm not following best practices when setting those defaults.
I do it now like this:
[Bindable] private var myColor2:uint = 0x000000;
[Bindable] private var myColor3:uint = 0x000000;
[Bindable] private var myValue:Number = 10.0;
then in the init function, I do a variation of this to set the default
myValue = hostComponent.value;
myValue = (hostComponent.value) ? hostComponent.value : 4.5;
Sometimes it works, sometimes it doesn't, depending on the type of variable I'm trying to set. I eventually decided to read them as Strings then convert them to the desired type, but it seems that this also works half the time.
© Stack Overflow or respective owner