Setting the corner radius a Spark Rect shape in Flex 4

In a previous example, “Setting a corner radius on individual corners on a Rect in Flex 4”, we saw how you could individually set the corner radius on each corner of a Spark Rect shape in Flex 4 by setting the topLeftRadiusX, topRightRadiusX, bottomLeftRadiusX, and bottomRightRadiusX properties.

The following example shows how you can set the corner radius on all corners of a Spark Rect shape in Flex 4 by setting the radiusX and radiusY properties.

The following example(s) require Flash Player 10 and the Adobe Flex 4 SDK. To download the Adobe Flash Builder 4 trial, see www.adobe.com/products/flex/. To download the latest nightly build of the Flex 4 SDK, see opensource.adobe.com/wiki/display/flexsdk/Download+Flex+4.

For more information on getting started with Flex 4 and Flash Builder 4, see the official Adobe Flex Team blog.

<?xml version="1.0" encoding="utf-8"?>
<!-- http://blog.flexexamples.com/2010/04/22/setting-the-corner-radius-a-spark-rect-shape-in-flex-4/ -->
<s:Application name="Spark_Rect_radiusX_test"
        xmlns:fx="http://ns.adobe.com/mxml/2009" 
        xmlns:s="library://ns.adobe.com/flex/spark" 
        xmlns:mx="library://ns.adobe.com/flex/mx">
    <s:controlBarContent>
        <mx:Form>
            <mx:FormItem label="radiusX:">
                <s:HSlider id="sldr1" maximum="40" />
            </mx:FormItem>
            <mx:FormItem label="radiusY:">
                <s:HSlider id="sldr2" maximum="40" />
            </mx:FormItem>
        </mx:Form>
    </s:controlBarContent>
 
    <s:Rect id="rct"
            radiusX="{sldr1.value}"
            radiusY="{sldr2.value}"
            width="160" height="120"
            horizontalCenter="0" verticalCenter="0">
        <s:fill>
            <s:SolidColor color="red" alpha="0.3" />
        </s:fill>
    </s:Rect>
 
</s:Application>

[GoogleAdsWide]

View source is enabled in the following example.

Or you can set the radiusX and radiusY properties using ActionScript, as seen in the following example:

<?xml version="1.0" encoding="utf-8"?>
<!-- http://blog.flexexamples.com/2010/04/22/setting-the-corner-radius-a-spark-rect-shape-in-flex-4/ -->
<s:Application name="Spark_Rect_radiusX_test"
        xmlns:fx="http://ns.adobe.com/mxml/2009" 
        xmlns:s="library://ns.adobe.com/flex/spark" 
        xmlns:mx="library://ns.adobe.com/flex/mx">
    <s:controlBarContent>
        <mx:Form>
            <mx:FormItem label="radiusX:">
                <s:HSlider id="sldr1" maximum="40" change="sldr1_changeHandler(event);" />
            </mx:FormItem>
            <mx:FormItem label="radiusY:">
                <s:HSlider id="sldr2" maximum="40" change="sldr2_changeHandler(event);" />
            </mx:FormItem>
        </mx:Form>
    </s:controlBarContent>
 
    <fx:Script>
        <![CDATA[
            protected function sldr1_changeHandler(evt:Event):void {
                rct.radiusX = sldr1.value;
            }
 
            protected function sldr2_changeHandler(evt:Event):void {
                rct.radiusY = sldr2.value;
            }
        ]]>
    </fx:Script>
 
    <s:Rect id="rct"
            width="160" height="120"
            horizontalCenter="0" verticalCenter="0">
        <s:fill>
            <s:SolidColor color="red" alpha="0.3" />
        </s:fill>
    </s:Rect>
 
</s:Application>

This entry is based on a beta version of the Flex 4 SDK and therefore is very likely to change as development of the Flex SDK continues. The API can (and will) change causing examples to possibly not compile in newer versions of the Flex 4 SDK.

One thought on “Setting the corner radius a Spark Rect shape in Flex 4

  1. Good night,
    Cara este seu blog é muito show.
    “Eu sou do Brasil.”
    “I’m from Brasil.”

Comments are closed.