Applying new skins to a subcomponent

In certain situations you may want to modify the skins of a subcomponent in a component, but the skin properties are not directly available (for example, there is no direct way to alter the skins of the scroll bar in a List component). The following code lets you access the scroll bar skins. All the scroll bars that are created after this code runs will also have the new skins.

If a component is composed of subcomponents, the subcomponents are identified in the component's entry in the ActionScript 2.0 Components Language Reference.

To apply a new skin to a subcomponent:

  1. Follow the steps in Creating new component skins, but edit a scroll bar skin. For this example, edit the ScrollDownArrowDown skin and give it the new name MyScrollDownArrowDown.
  2. Select File > New to create a new Flash document.
  3. Select File > Save and give the file a unique name, such as SubcomponentProject.fla.
  4. Drag the List component in the Components panel to the library.

    This adds the component to the Library panel, but doesn't make the component visible in the document.

  5. Drag MyScrollDownArrowDown and any other symbols you edited from MyTheme.fla to the library of SubcomponentProject.fla.

    This adds the symbol to the Library panel, but doesn't make it visible in the document.

  6. Do one of the following:
  7. Select Control > Test Movie.

You can also set subcomponent skins for all components in a document by setting the skin property on the subcomponent's prototype object in the #initclip section of a skin symbol.

To use #initclip to apply an edited skin to all components in a document:

  1. Follow the steps in Creating new component skins, but edit a scroll bar skin. For this example, edit the ScrollDownArrowDown skin and give it the new name MyScrollDownArrowDown.
  2. Select File > New and create a new Flash document. Save it with a unique name, such as SkinsInitExample.fla.
  3. Select the MyScrollDownArrowDown symbol from the library of the edited theme library example, drag it to the library of SkinsInitExample.fla.

    This adds the symbol to the library without making it visible on the Stage.

  4. Select MyScrollDownArrowDown in the SkinsInitExample.fla library, and select Linkage from the Library options menu.
  5. Select the Export for ActionScript check box. Click OK.

    Export in First Frame should be automatically selected; if it is not, select it.

  6. Double-click MyScrollDownArrowDown in the library to open it in symbol-editing mode.
  7. Enter the following code on Frame 1 of the MyScrollDownArrowDown symbol:
    #initclip 10
        import mx.controls.scrollClasses.ScrollBar;
        ScrollBar.prototype.downArrowDownName = "MyScrollDownArrowDown";
    #endinitclip
    
  8. Do one of the following to add a List component to the document:

The following example explains how to skin something that's already on the Stage. This example skins only List scroll bars; any TextArea or ScrollPane scroll bars would not be skinned.

To use #initclip to apply an edited skin to specific components in a document:

  1. Follow the steps in Editing component skins in a document, but edit a scroll bar skin. For this example, edit the ScrollDownArrowDown skin and give it the new name MyScrollDownArrowDown.
  2. Select File > New and create a Flash document.
  3. Select File > Save and give the file a unique name, such as MyVScrollTest.fla.
  4. Drag MyScrollDownArrowDown from the theme library to the MyVScrollTest.fla library.
  5. Select Insert > New Symbol and give the symbol a unique name, such as MyVScrollBar.
  6. Select the Export for ActionScript check box. Click OK.

    Export in First Frame should be automatically selected; if it is not, select it.

  7. Enter the following code on Frame 1 of the MyVScrollBar symbol:
    #initclip 10
        import MyVScrollBar
        Object.registerClass("VScrollBar", MyVScrollBar);
    #endinitclip
    
  8. Drag a List component from the Components panel to the Stage.
  9. In the Property inspector, enter as many Label parameters as necessary for the vertical scroll bar to appear.
  10. Select File > Save.
  11. Select File > New and create a new ActionScript file.
  12. Enter the following code:
    import mx.controls.VScrollBar
    import mx.controls.List
    class MyVScrollBar extends VScrollBar{
        function init():Void{
            if (_parent instanceof List){
                downArrowDownName = "MyScrollDownArrowDown";
            }
            super.init();
        }
    }
    
  13. Select File > Save and save this file as MyVScrollBar.as.
  14. Click a blank area on the Stage and, in the Property inspector, click the Publish Settings button.
  15. Click the ActionScript Version Settings button.
  16. Click the Add New Path (+) button to add a new classpath, and select the Target button to browse to the location of the MyVScrollBar.as file on your hard disk.
  17. Select Control > Test Movie.

Flash CS3