Skinning Without Code
Skinning Without Code
Visually skinning components usually involves modifying library symbols to represent what you want a component to look like. Many long-time Flash users were surprised that they couldn’t readily find component symbols in the library when including a component in their project.
The introduction of the SWC (a compiled form of a component that is used to package all component assets into one convenient file) file format in Flash MX 2004 allowed us to easily package components and distribute them, which is a great benefit. At the same time, however, the skins, which are required for each component, are also included in the SWC. Since you can’t edit the contents of an SWC file, you must add the library symbols to redefine those symbols.
By adding symbols to your library with the same linkage IDs that the skin property is set to (usually the default value of the component), a component would use that symbol over the symbol included within the SWC file for its skin. You might be thinking this is a pretty tedious task (i.e., manually tracking down the Linkage IDs, creating each symbol, and making sure you don’t make mistakes along the way), but thankfully Macromedia has provided us with a starting point to help ease the process.
The StandardComponents.FLA file is included with every installation of Flash and is located in C:Program FilesMacromediaFlash MX 2004enConfigurationComponentFLA (Windows) and Hard Drive/Users/ <username>/Library/Application Support/Macromedia/Flash MX 2004/ en/Configuration/ComponentFLA (OS X).
A Few Notes about Themes
In the latest version of Flash, Macromedia introduced the concept of themes. Before I discuss using themes to skin components, I’ll briefly explain the purpose of themes.
Themes are a collection of skins and styles that enable you to develop an overall look for a set of components. I will not look into how styles are implemented in themes, because my main focus is skinning. Themes work as mentioned above, by having a symbol in the library with the same Linkage ID as existing symbols within the component’s SWC. To make use of themes, Macromedia distributes the collection of library symbols in an FLA file as a starting point to work from.
The following steps explain how to include a theme:
- Create a new FLA file.
- Open the file HaloTheme.fla (in Windows, the file is located in the C:Program FilesMacromediaFlash MX 2004enConfigurationComponentFLA directory; in OS X you can find it under Hard Drive/Users/ <username>/Library/Application Support/Macromedia/Flash MX 2004/ en/Configuration/ComponentFLA ).
- Locate the main HaloTheme symbol in the library and drag it to the blank FLA file created in step 1.
- Select Themes > MMDefault > Window Assets to open the Window Assets symbol.
Customize the different graphical items in the symbol to your liking (see Figure 1).
- Drag a Window component onto the main Stage.
- Select Control > Test Movie to view the results.
Typically you would customize all the different symbols in a theme and have the complete theme available so you can easily reskin an application. Note also that at this time theme files are not only made up of graphical assets in the library, but can also be drawn through code including default component style values, as I will show shortly.
To briefly discuss styles in themes, you can check the HaloTheme library. You will notice a symbol called Defaults in Flash UI Components 2 > Themes > MMDefault of the library. If you check the linkage properties of the symbol you will find that the symbol is associated with a class. You can find that class files in the included Classes folder. Open the Default.as file located in C:Program FilesMacromediaFlash MX 2004enFirst RunClassesmxskinshalo (Windows) or (OS X) . You should know that the
setThemeDefaults() method is responsible for setting these defaults. If you want to build a complete theme, you might find it beneficial to specify the default styles of components as well. You can do so easily by customizing the Default.as file. If you plan to do so, ensure you create a local copy for your application. The files located in the global classes folder should never be modified.
Finally, if you want to skin only one component rather than have a whole theme, you could delete all library item files not related to the component you are interested in skinning and edit the symbol you want instead.
A Few Notes about Skinning Without Code
Skinning components without any code can be very limiting, but there are several things to keep in mind when trying to avoid writing code every time you want to skin a component:
For example, explore the file SampleTheme.fla which can be found in C:Program FilesMacromediaFlash MX 2004enConfigurationComponentFLA (Windows) or Hard Drive/Users/<username>/Library/Application Support/Macromedia/Flash MX 2004/en/Configuration/ComponentFLA (OS X). This theme can be easier to skin because it uses less code to draw the skins as apposed to the HaloTheme
Some components use the same values for multiple skin properties (component states), as they draw that skin using code. For those components, there is no method of customizing the different states independently without having to write some code. The Button component is a good example of this.