Macromedia flex 2 Manuale

Pagina di 254
Applying styles to your custom component
87
Class selectors
Type selectors
The styles that application developers can apply correspond to the styles supported by the root 
tag of the MXML component. The following example uses a tag property to set a style for the 
custom MXML component: 
<?xml version="1.0"?>
<!-- mxml/MainStyleWithPropsOverrideOpenDur.mxml -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" 
    xmlns:MyComp="myComponents.*">
    <MyComp:StateComboBoxWithStyleProps openDuration="1000"/>
    
</mx:Application>
When you specify styles as tag attributes, those styles override any conflicting styles set in the 
definition of the MXML component.
You can use a class selector to define styles. Often you use a class selector to apply styles to 
specific instances of a control, as the following example shows:
<?xml version="1.0"?>
<!-- mxml/MainStyleOverrideUsingClassSel.mxml -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" 
    xmlns:MyComp="myComponents.*">
    <mx:Style>
        .myStateComboBox {
            openDuration : 1000;
        }
    </mx:Style> 
    <MyComp:StateComboBoxWithStyleProps styleName="myStateComboBox"/>
    <mx:ComboBox>
        ...
    </mx:ComboBox>
</mx:Application>
In this example, you use the 
styleName
 property in the tag definition of an MXML 
component to apply styles to a specific instance of the MXML component. However, those 
styles are not applied to the 
ComboBox
 control defined in the main application file, nor 
would they be applied to any other instances of StateComboBox.mxml unless you also specify 
the 
styleName
 property as part of defining those instances of the MXML component.
When you specify any styles by using a class selector, those styles override all styles that you set 
by using a class selector in the MXML file. Those styles do not override styles that you set by 
using tag properties in the MXML file.