6 Replies Latest reply on Jul 20, 2009 7:08 PM by Michael Borbor

    Programmatically Skin a Component Issue

    Benoitcn Level 1

      I try to run one of the examples in Flex3 Cookbook. But the compiler said can't find the customed class that extends the Border class.

       

      package oreilly.cookbook
      {
          import mx.graphics.RectangularDropShadow;
          import mx.skins.Border;
      
          public class CustomBorder extends Border
          {
              private var _dropShadow:RectangularDropShadow;
              private static const CNR_RAD:Number = 5;
              private static const POINT_POS:String = 'bl';
              private static const BG_COL:uint = 0x336699;
              private static const BG_ALPHA:Number = 1.0;
      
              public function CustomBorder()
              {
                  super();
                  _dropShadow = new RectangularDropShadow();
              }
      
              private function getCornerRadiusObj( rad:Number, pointPos:String ):Object
              {
                  var pt:String = pointPos ? pointPos : POINT_POS;
                  return {tl:rad, bl:0, tr:rad, br:rad};
              }
      
              override protected function updateDisplayList( unscaledWidth:Number,
                                                             unscaledHeight:Number ):void
              {
                  super.updateDisplayList( unscaledWidth, unscaledHeight );
                  var cornerRadius:Number = getStyle( "cornerRadius" ) ?
                                              getStyle( "cornerRadius" ) :
                                              CustomBorder.CNR_RAD;
                  var backgroundColor:Number = getStyle( "backgroundColor" ) ?
                                              getStyle( "backgroundColor" ) :
                                              CustomBorder.BG_COL;
                  var backgroundAlpha:Number = getStyle( "backgroundAlpha" ) ?
                                              getStyle( "backgroundAlpha" ) :
                                              CustomBorder.BG_ALPHA;
      
                  var cnrRadius:Object = getCornerRadiusObj( cornerRadius,
                                              getStyle( "pointPosition" ) );
                  graphics.clear();
                  drawRoundRect( 0, 0, unscaledWidth, unscaledHeight,
                                  cnrRadius , backgroundColor, backgroundAlpha );
      
                  _dropShadow.tlRadius = cnrRadius.tl;
                  _dropShadow.blRadius = cnrRadius.bl;
                  _dropShadow.trRadius = cnrRadius.tr;
                  _dropShadow.brRadius = cnrRadius.br;
                  _dropShadow.drawShadow( graphics, 0, 0,
                                              unscaledWidth, unscaledHeight );
              }
          }
      }
      
      
      <?xml version="1.0" encoding="utf-8"?>
      <mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="init()">
           <mx:Script>
                <![CDATA[
                     import oreilly.cookbook.CustomBorder;
      
                     private function init():void
                     {
                          var b:CustomBorder = new CustomBorder();
                     }
                ]]>
           </mx:Script>
      </mx:WindowedApplication>