A UIComponent gets its styles by calling the getStyle() method that it inherits from UIComponent, not the getStyle() method on CSSStyleDeclaration. I'll try to explain the difference.

 

The getStyle() method on CSSStyleDeclaration simply looks at the styles set in that single CSSStyleDeclaration object., which represents a single CSS type selector like

 

    Button { color: red }

 

or a single CSS class selector like

 

    .red { color: red }

 

By contrast, the getStyle() method on UIComponent searches a whole chain of style-containing objects, stopping when it finds the style defined somehwere. First it looks at the styles set on that instance. Then it looks in the styles defined by the class selector. Then it looks in the styles defined by the type selector for the component's class (or if that doesn't exist, for the type selector of its superclass, etc.). Then, if it is an inheriting style, the process continues with the component's parent container, and its parent container, etc., up to the application object. Finally, it looks in the global styles.

 

This chain of style-containing objects is sometimes called the "style prototype chain" because each object links to the next one via the ECMAScript "prototype" property on every Object. (Actually, there are two chains, whose starting points are the objects _inheritingStyles and _nonInheritingStyles on UIComponent.) This means that a call like getStyle("color") can be implemented as a single property lookup, _inheritingStyles["color"], which will search the entire chain at C++ speed. in the player! Is that cool or what? The "prototype" property is a legacy of ECMAScript-style "prototype-based inheritance", which is otherwise barely used in ActionScript 3 because AS3 introduced class-based inheritance.

 

The objects in this style prototype chain are not CSSStyleDeclaration instances, but rather style-containing objects produced by the factory functions in those CSSStyleDeclaration instances.

 

So... if you really want to change style lookup, you could override UIComponent's public getStyle() method or UIComponent's initProtoChain() method, which is undocumented and subject to change, but lives in the mx_internal namespace.

 

- Gordon

 


From: [email protected] [mailto:[EMAIL PROTECTED] On Behalf Of sergio_trejo_r
Sent: Monday, August 14, 2006 7:43 AM
To: [email protected]
Subject: [flexcoders] Extending CSSStyleDeclaration

 

Is there a way to extend the CSSStyleDeclaration class in such a way
that I can store/calculate the style values in my application?

For example, I want to create a style CSS1 that depends on a different
style CSS0. If a style property is not assigned to CSS1 then it
should get the value from the parent style CSS0. If a style property
is assigned to CSS1 then it should just return the value.

I tried creating a subclass of CSSStyleDeclaration and overriding the
getStyle and setStyle methods. However, after applying the style
declaration to a UIComponent, the component does not call the getStyle
method on the style declaration so loose the oportunity to override
the behavior. After debugging for a while it looks like the UI
component calls a private method in the style declaration
'addStyleToProtoChain' which I can not override.

Is there any other way to customize the Style subsystem?

Thanks.

__._,_.___

--
Flexcoders Mailing List
FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.com





SPONSORED LINKS
Software development tool Software development Software development services
Home design software Software development company


YAHOO! GROUPS LINKS




__,_._,___

Reply via email to