Cropping / cropping

How to crop / crop on Sprite in Flex?

<?xml version="1.0" encoding="utf-8"?>
<mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical" creationComplete="Init()">
  <mx:Script>
    <![CDATA[
      public function Init():void {
        var spr:Sprite=new Sprite();
        uic.addChild(spr);
        uic.graphics.lineStyle(2,0);
        uic.graphics.moveTo(22, 22);
        uic.graphics.lineTo(2222, 2222);
      }
    ]]>
 </mx:Script>
 <mx:Panel title="StackOverflow">
    <mx:UIComponent width="200" height="200" id="uic"/>
  </mx:Panel>
</mx:WindowedApplication>

Note that lineTo completely leaves UIComponent and Panel.

How can I make crop / crop my UIComponent or Sprite or Panel? alt text http://www.liquidfeline.com/images/stackoverflow.png

I understand that I can just change the hard-coded 2222 to something more reasonable, but I need a generalized solution to this, since in the actual project there are no hard-coded values ​​that I can change, but it works with dynamic data.

+3
source share
2 answers

Use a mask.

var mask:Shape = new Shape();
with(mask.graphics)
{
    beginFill(0xFFFFFF, 1); // white, opaque
    drawRect(0, 0, width, height);
    endFill();
}
uic.mask = mask;
+2
source

scrollRect, , . scrollRect Grant Skinner.

+5

Source: https://habr.com/ru/post/1753451/