actionscript自定义组件,属性:

   
   
   
   
  1. package contr  
  2. {  
  3.     import spark.components.BorderContainer;  
  4.       
  5.     public class Ruler extends BorderContainer  
  6.     {  
  7.         private var _lineLength:Number;  
  8.           
  9.         private var _spacing:Number;  
  10.         private var _scale:Number;  
  11.           
  12.         public function Ruler()  
  13.         {  
  14.             super();  
  15.         }  
  16.  
  17.         /**定义最小显示刻度*/  
  18.         public function get scale():Number  
  19.         {  
  20.             return _scale;  
  21.         }  
  22.  
  23.         /**  
  24.          * @private  
  25.          */  
  26.         public function set scale(value:Number):void  
  27.         {  
  28.             _scale = value;  
  29.         }  
  30.  
  31.         /**定义最小间距*/  
  32.         public function get spacing():Number  
  33.         {  
  34.             return _spacing;  
  35.         }  
  36.  
  37.         /**  
  38.          * @private  
  39.          */  
  40.         public function set spacing(value:Number):void  
  41.         {  
  42.             _spacing = value;  
  43.         }  
  44.  
  45.         /**定义线条的长度*/  
  46.         public function get lineLength():Number  
  47.         {  
  48.             return _lineLength;  
  49.         }  
  50.  
  51.         /**  
  52.          * @private  
  53.          */  
  54.         public function set lineLength(value:Number):void  
  55.         {  
  56.             _lineLength = value;  
  57.         }  
  58.  
  59.     }  

效果:

   
   
   
   
  1. xml version="1.0" encoding="utf-8"?> 
  2. <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"   
  3.                xmlns:s="library://ns.adobe.com/flex/spark"   
  4.                xmlns:mx="library://ns.adobe.com/flex/mx"   
  5.                xmlns:con="contr.*" 
  6.                minWidth="955" minHeight="600"> 
  7.     <fx:Declarations> 
  8.          
  9.     fx:Declarations> 
  10.     <mx:VBox width="100%" height="100%" > 
  11.         <con:Ruler lineLength="200" scale="5" spacing="10"/> 
  12.     mx:VBox> 
  13. s:Application> 

 

flex 学习笔记 as自定义组件(三)_第1张图片