Flash CS3 Documentation |
|||
| Using ActionScript 2.0 Components > Customizing Components > Combining skinning and styles to customize a component | |||
In this section, you will customize a combo box component instance using styles, themes, and skinning settings. The procedures demonstrate how to combine skinning with style settings to create a unique presentation for a component.
The first part of this exercise requires you to create a ComboBox instance for customizing.
my_cb.addItem({data:1, label:"One"});
my_cb.addItem({data:2, label:"Two"});
Now, you need to create a new style declaration and assign styles to the style declaration. After you have all the styles you want in the style declaration, you can assign the new style name to the combo box instance.
import mx.styles.CSSStyleDeclaration;
var new_style:Object = new CSSStyleDeclaration(); _global.styles.myStyle = new_style;
After you assign a new style declaration to the _global style sheet, you can attach individual style settings to the new_style style declaration. For more information about creating a style sheet for groups for components, instead of style definitions for a single instance, see Setting custom styles for groups of components).
new_style style declaration. The following style settings include style definitions available to the ComboBox component (see Using styles with the ComboBox component in the ActionScript 2.0 Components Language Reference for more a complete list) as well as styles from the RectBorder class, since the ComboBox component uses the RectBorder class:
new_style.setStyle("textAlign", "right");
new_style.setStyle("selectionColor", "white");
new_style.setStyle("useRollOver", false);
// borderStyle from RectBorder class
new_style.setStyle("borderStyle", "none");
At this point, you have a style declaration containing a variety of styles, but you need to explicitly assign the style name to the component instance. You can assign this new style declaration to any component instance within your document in the following manner. Add the following line after the addItem() statements for my_cb (as a coding convention, you should keep all your combo box construction statements together):
my_cb.setStyle("styleName", "myStyle");
The ActionScript code attached to the first frame of the main Timeline should be as follows:
import mx.styles.CSSStyleDeclaration;
var new_style:Object = new CSSStyleDeclaration();
_global.styles.myStyle = new_style;
new_style.setStyle("textAlign", "right");
new_style.setStyle("selectionColor", "white");
new_style.setStyle("useRollOver", false);
// borderStyle from RectBorder class
new_style.setStyle("borderStyle", "none");
my_cb.addItem({data:1, label:"One"});
my_cb.addItem({data:2, label:"Two"});
my_cb.setStyle("styleName", "myStyle");
Select Control > Test Movie to see the styled combo box:
Every user interface component lists the style properties you can set for that component (for example, all the style properties you can set for a ComboBox component are listed in Customizing the ComboBox component in the ActionScript 2.0 Components Language Reference). Within the table of style properties, a column titled "Theme" shows which installed theme supports each style property. Not all the style properties are supported by all the installed themes. The default theme for all user interface components is the Halo theme. When you change the theme to the Sample theme, you can use a different set of style properties (some properties may no longer be available if they are listed as Halo only).
This file is located in the application-level configuration folder:
The ComboBox component is a combination of several components and classes, and requires assets from those other components and assets, including the Border and ScrollBar assets. The simplest way to ensure that you have all the assets from a theme that you need is to drag all the theme's assets to your library.
To edit the appearance of a component, edit the skins that comprise the component, graphically. To edit the skins, you open the component's graphic assets from within the current theme, and edit the symbols for that component. Adobe recommends this approach because it doesn't remove or add symbols that other components might need; this approach edits the appearance of an existing component skin symbol.
|
NOTE |
|
It is possible, but not recommended, to edit the source class files for a component so it uses symbols with different names as skins, and you can programmatically alter the ActionScript within a skin symbol (for an example of customized ActionScript and skin symbols, see Customizing the Accordion component in the ActionScript 2.0 Components Language Reference). However, because several components, including the ComboBox component, share assets with other components, editing the source files or changing the skin symbol names can have unexpected results. |
When you edit a component skin symbol:
In this section, you will continue to use the combo box from the previous section (see Changing the combo box theme). The following steps change the appearance of the down arrow that opens the combo box menu from an arrow to a circle.
The States folder contains four movie clips: ComboDownArrowDisabled, ComboDownArrowDown, ComboDownArrowOver, and ComboDownArrowUp. All four of these symbols are made up of other symbols. And all four use the same symbol for the down arrow (triangle), called SymDownArrow.
You may need to zoom in, up to 800%, to see the details for the button.
|
NOTE |
|
Make sure you have the symbol SymDownArrow selected, so you are deleting only the shape inside the movie clip and not the movie clip symbol, itself. |
To make the change more noticeable, consider drawing a circle that is a bright color, like blue, approximately 4 pixels x 4 pixels, and with an x coordinate of 0 and a y coordinate of -1 so it is centered.
In your document's library, if you select ComboDownArrowOver and ComboDownArrowUp, you'll see that they also have the blue circle instead of the black triangle, because they also use SymDownArrow for the down arrow symbol.
Flash CS3