2013-03-14 51 views
0

我想繪製一些線條,他們不能跨面板邊框,我不知道該怎麼做... 線條越過了面板邊框,但我希望該線條進入面板,然後我會可以放大它。 這裏是我的代碼:如何在Flex中繪製不超出面板邊界?

<?xml version="1.0" encoding="utf-8"?> 
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
       xmlns:s="library://ns.adobe.com/flex/spark" 
       xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600" 
       > 

<fx:Script> 
    <![CDATA[ 
     import mx.graphics.SolidColorStroke; 

     import spark.primitives.Line; 



     private function drawLine():void 
     { 
      var myShape:Shape = new Shape(); 
      myShape = new Shape() ; 


      myShape.graphics.lineStyle(2, 0x00008B, .75); 
      myShape.graphics.moveTo(500, 500); 

      myShape.graphics.lineTo(25, 45); 
      spr.addChild(myShape); 
     } 
    ]]> 
</fx:Script> 


<mx:Button label="Click" click="drawLine()" /> 
<s:Panel y="30" width="400" height="250" layout="vertical" title="Panel" borderColor="#008040" fontFamily="Arial" fontWeight="bold" fontSize="13"> 

<mx:Text text="Drawing.." fontWeight="bold"/> 
     <s:SpriteVisualElement width="500" height="500" id="spr"/> 
</s:Panel> 
</s:Application> 

回答

0

一個簡單的方法是把內容放在Group並設置clipAndEnableScrolling

<s:Panel> 
    <s:VGroup height="100%" width="100%" clipAndEnableScrolling="true"> 
     <mx:Text text="Drawing.." fontWeight="bold"/> 
     <s:SpriteVisualElement width="500" height="500" id="spr"/>    
    </s:VGroup> 
</s:Panel>