Amy,

When you get the value of the style, you need to store it in an untyped
variable. This will allow you to check for undefined. If you store the value
in an int, uint or Boolean, for example, it will be converted from
undefinedto the default value of that type (0, 0, or
false, respectively).
 var myStyle:* = getStyle("myStyle");
if (myStyle == undefined) {
 myStyle = 42; // appropriate default
}
 var myStyleUntyped:* = getStyle("myStyle");
var myStyle:int = 42; // appropriate default
if (myStyle != undefined) {
 myStyle = myStyleUntyped;
}

You could also store the value in a variable typed Object. In my testing, I
found that this stores null instead of undefined because an Object cannot be
undefined. Only an untyped variable or an nonexistent property can be
undefined.

Actionscript has strict rules about what values can be assigned to variables
of specific types. The undefined and null values, in particular, cannot be
assigned to many of the basic types. Only an untyped variable can be
undefined and only variables that represent classes which are descendants of
Object can be null. Numeric variables such as int and uint always have a
value. The Number type can be NaN, but is never null or undefined. The
String type can be null, but not undefined. The Boolean type must always be
true or false and is never null or undefined.

These rules help limit the number of edge cases in the language and the
impact of uninitialized variables, but can also be confusing.
-Jonathan

(Posted online at http://jonathanbranam.net/solutions/check-unset-styles)
Short link:
http://jonathanbranam.net/node/51

http://jonathanbranam.net - Flex 3 Anatomy and Solutions


On Wed, Jun 25, 2008 at 4:13 PM, Amy <[EMAIL PROTECTED]> wrote:

>   --- In [email protected] <flexcoders%40yahoogroups.com>,
> "Michael Schmalle"
> <[EMAIL PROTECTED]> wrote:
> >
> > Hi,
> >
> > try using isNaN()
> >
> > if (isNaN(_myColor)){
> > //do something when NaN
> > }else{
> > //do another thing when is a color
> > }
>
> I actually wound up just comparing straight to the getStyle() result
> and comparing that to undefined, since that's what it is when it
> isn't set. I haven't been able to find any examples that show
> different ways of dealing with keywords, etc., so I figured that was
> the safest way.
>
> And thanks :-)
>
> -Amy
>
>  
>

Reply via email to