Hi Judah,
You should made a clear distinction in your custom component between setting
default values to public styles and public properties.
In your example, "editable" is a property of Boolean type, but "borderStyle"
is a style and they should be treated in a different way.
You can set default value to "editable" property straight in the constructor
of your ActionScript class like:
public function Countdown():void {
super();
editable = true;
}
The default value for the style "borderStyle" in your custom component
should be set in a different way:
Correct and only solution that work always for inherited styles and your
added custom styles:
----------------------------------------------------------------------------------------------------------------------------------------
You have to set up a static initializer to create the default value for your
styles like:
----------------------------------------------------------------------------------------------------------------------------------------
// Define a static variable.
private static var classConstructed:Boolean = classConstruct();
// Define a static method.
private static function classConstruct():Boolean {
if (!StyleManager.getStyleDeclaration("Countdown"))
{
// If there is no CSS definition for Countdown,
// then create one and set the default value.
var newStyleDeclaration:CSSStyleDeclaration =
new CSSStyleDeclaration();
newStyleDeclaration.setStyle("borderStyle", "none");
StyleManager.setStyleDeclaration("Countdown",
newStyleDeclaration, true);
}
return true;
}
This workflow is documented here:
http://livedocs.adobe.com/flex/201/html/skinstyle_149_7.html
after Manish Jethani has requested the documentation update at
http://bugs.adobe.com/jira/browse/FLEXDOCS-149 (cudos to Manish!)
Cumbersome?
Absolutely, yes!
Go vote on http://bugs.adobe.com/jira/browse/SDK-662 issue if you want to
get this changed in Flex 4 SDK release
--
--
Med venlig hilsen / Best regards
Andriy Panas
[EMAIL PROTECTED]
On 18/05/2008, dorkie dork from dorktown <[EMAIL PROTECTED]>
wrote:
>
> I am converting an MXML component that extends textinput to a AS3
> Component Class that extends the TextInput. In the MXML version I am setting
> the properties right in the MXML tags like so:
>
> <?xml version="1.0" encoding="utf-8"?>
> <mx:TextInput xmlns:mx="http://www.adobe.com/2006/mxml"
> editable="false"
> borderStyle="none"
> text="1 day 23 hours 59 minutes 59 seconds"
> backgroundAlpha="0"
> initialize="init()"
> creationComplete="created()">
>
> How and where would I set the default values in my AS3 class? For example,
> "editable" and "borderStyle"?
>
>
> public class Countdown extends TextInput {
>
> // set new default values
> //public var editable:Boolean = false; //throws errors
> public var borderStyle:String = "none"; //doesn't apply
> //public var text:String = "1 day 23 hours 59 minutes 59 seconds";
> // throws error
> public var backgroundAlpha:Number = 0; //doesn't apply
>
> public function Countdown():void {
> //TODO: implement function
> super();
> }
> }
>
>
>
>