23.4.07

Booleans - Disturbingly Little

Nice



My apologies to all of you programmers out there who have been developing in real languages all along.

Today I posted to flexcoders that I was a little disturbed by the fact that Booleans initialize to false. Prior to AS3 you could compare a Boolean to undefined. The Flex compiler seems to complain if you even think about Booleans as undefined or null:

"1184: Incompatible default value of type Null where Boolean is expected..."
when creating this function: public function f(b:Boolean = null)

"1012: Variables of type Boolean cannot be undefined... (e.g. )"
when making this comparison: b==undefined

Nice that it acts more like a real programming language, not nice that I have to mend my AS2 ways of using the absence of assignment as some third value for a boolean. In hind-sight, this isnt good programming practice anyway because it requires interpretation to understand the third meaning. Interpretation is always a maintenance nightmare.

End of the day flexcoders answered with something I needed to hear: "use an enum". Don't think the thought wasnt met with some resistance.

"Enum? Shoo-oo-oot those aint in achunscript"

Now earlier today I had concrete ideas about what an Enum is, but I have no real experience creating one. This always drives me nuts because our minds are designed to constantly spin problems with our spare processor cycles (kind of like SETI@home) Unfortunately this intra terrestrial activity tends to reduce the amount of good sleep I get... and it keeps me up at night.

I dove in and came up with an enum example that you can extend to create your own enums. This is pretty straight forward.

I personally think you grasp something 70% by using it 20% by creating it and maybe if you're lucky, 10% wondering about it. In any case, it will be really nice to spend time using enums instead of over-rethinking this really simple concept.

12.4.07

allowNetworking
all | internal | none

Sweet


I recently created a widget for MySpace and other community sites. Some of these sites force the community posting flash widgets to set the object allowNetworking attribute to 'internal'. I needed to know ahead of time wether I could just provide a link or if I would need a button to allow the user to copy the destination to the clipboard.

I couldn't find a built in function to check the value ahead of time, but I noticed that when I tried to call navigateToUrl with this attribute set to 'internal' or 'none', Flex throws a SecurityError...

Cool, using this knowledge I created a simple function that tries to call navigateToUrl with an empty url. Flash won't try to go to '' (empty string) but navigateToUrl still throws the SecurityError. So my function uses a simple try/catch/finally to return true or false.

Check out the sample code here:

allowNetworking Sample

Let me know if AS3 provides other means for testing this value, I couldn't find one.