The first CS3 component tip is really a bug in the authoring environment. It has to do with inspectable getters and setters and default values.
These are done pretty much identically to the way they were done in the old V2 components. Say you want a component parameter that will show up in the Properties Inspector. You give it a metadata tag of Inspectable. There are various parameters you can set here, such as type, defaultValue, etc. This would go right before either the getter or setter. You only have to define it once.
[as][Inspectable (defaultValue=99)]
public function set bottlesOfBeer(value:Number):void
{
_bottlesOfBeer = value;
}
public function get bottlesOfBeer():Number
{
return _bottlesOfBeer;
}[/as]
Now, that property will be shown in the Properties Inspector and the Component Inspector when the component on stage is selected. For a brand new component on stage, the default value will be filled in already. If no default value is specified, there are “default” default values depending on the type: String is “”, any number types are 0, Boolean is false, color is #000000, arrays are null, and a list would be the first value in the enumeration.
Theoretically, what happens is that when the movie is run, the setter is called. This occurs after the constructor is called. However, here is the gotcha:
This has a couple of repercussions.
Unfortunately, number one above results in code duplication, as you need to define the default value for the variable, and then set the default value for the inspectable parameter, which should be the same, and if you change one, you need to change them both. I know what you are thinking: use a variable to define the defaultValue, which can be the same private variable the setter is setting, like so:
[as]private var _bottlesOfBeer:Number = 99;
[Inspectable (defaultValue=_bottlesOfBeer)]
public function set bottlesOfBeer(value:Number):void
{
_bottlesOfBeer = value;
}
public function get bottlesOfBeer():Number
{
return _bottlesOfBeer;
}[/as]
But the metadata tag doesn’t have access to the class properties. So it takes _bottlesOfBeer as the string, “_bottlesOfBeer”. If your setter is a string, that’s the string it will get. In this case, the string gets evaluated as 0, so rather than 99, your default value becomes 0.
Not the end of the world. Just something to keep in mind, and a bit of necessary duplication.