Macromedia flex 2 Manual

Page of 254
176
Creating Advanced Visual Components in ActionScript
The following example shows the ModalText.as file that defines this control:
package myComponents

    // Import all necessary classes.
    import mx.core.UIComponent;
    import mx.controls.Button;
    import mx.controls.TextArea;
    import flash.events.Event;
    import flash.text.TextLineMetrics;
    // ModalText dispatches a change event when the text of the child 
    // TextArea control changes, a textChanged event when you set the text 
    // property of ModalText, and a placementChanged event
    // when you change the textPlacement property of ModalText. 
    [Event(name="change", type="flash.events.Event")]
    [Event(name="textChanged", type="flash.events.Event")]
    [Event(name="placementChanged", type="flash.events.Event")]
    
    /*** a) Extend UIComponent. ***/
    public class ModalText extends UIComponent {
        /*** b) Implement the class constructor. ***/
        public function ModalText() {
            super();
        }
        /*** c) Define variables for the two child components. ***/ 
        // Declare two variables for the component children.
        private var text_mc:TextArea;
        private var mode_mc:Button;
        
        /*** d) Embed new skins used by the Button component. ***/
        // You can create a SWF file that contains symbols  with the names  
        // ModalUpSkin, ModalOverSkin, and ModalDownSkin.       
        // If you do not have skins, comment out these lines.
        [Embed(source="Modal2.swf", symbol="blueCircle")]
        public var modeUpSkinName:Class;
    
        [Embed(source="Modal2.swf", symbol="blueCircle")]
        public var modeOverSkinName:Class;
        [Embed(source="Modal2.swf", symbol="greenSquare")]
        public var modeDownSkinName:Class;
        /*** e) Implement the createChildren() method. ***/
        // Test for the existence of the children before creating them.
        // This is optional, but we do this so a subclass can create a