Quantcast
Channel: Flex Examples » cornerRadius
Viewing all articles
Browse latest Browse all 10

Setting the corner radius on the Spark TitleWindow container in Flex 4

$
0
0

The following example shows how you can set the corner radius on the Spark TitleWindow container in Flex 4 by setting the cornerRadius style.

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/27/setting-the-corner-radius-on-the-spark-titlewindow-container-in-flex-4/ -->
<s:Application name="Spark_TitleWindow_cornerRadius_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:layout>
        <s:HorizontalLayout horizontalAlign="center" verticalAlign="middle" />
    </s:layout>
    <s:controlBarContent>
        <s:Label text="cornerRadius:" />
        <s:HSlider id="sl" maximum="15" />
    </s:controlBarContent>
 
    <s:TitleWindow id="tw1"
            title="Spark TitleWindow without control bar"
            cornerRadius="{sl.value}"
            controlBarVisible="true"
            width="250" height="120"
            horizontalCenter="0" verticalCenter="0">
        <s:Label text="Spark TitleWindow contents" left="10" top="10" />
    </s:TitleWindow>
 
    <s:TitleWindow id="tw2"
            title="Spark TitleWindow with control bar"
            cornerRadius="{sl.value}"
            controlBarVisible="true"
            width="250" height="120"
            horizontalCenter="0" verticalCenter="0">
        <s:controlBarContent>
            <s:Label text="Control bar content" />
        </s:controlBarContent>
        <s:Label text="Spark TitleWindow contents" left="10" top="10" />
    </s:TitleWindow>
 
</s:Application>

[GoogleAdsWide]

View source is enabled in the following example.

You can also set the cornerRadius style in an external .CSS file or <Style/> block, as seen in the following example:

<?xml version="1.0" encoding="utf-8"?>
<!-- http://blog.flexexamples.com/2010/04/27/setting-the-corner-radius-on-the-spark-titlewindow-container-in-flex-4/ -->
<s:Application name="Spark_TitleWindow_cornerRadius_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:layout>
        <s:HorizontalLayout horizontalAlign="center" verticalAlign="middle" />
    </s:layout>
 
    <fx:Style>
        @namespace s "library://ns.adobe.com/flex/spark";
        @namespace mx "library://ns.adobe.com/flex/mx";
 
        s|TitleWindow {
            cornerRadius: 15;
        }
    </fx:Style>
 
    <s:TitleWindow id="tw1"
                   title="Spark TitleWindow without control bar"
                   controlBarVisible="true"
                   width="280" height="120"
                   horizontalCenter="0" verticalCenter="0">
        <s:Label text="Spark TitleWindow contents" left="10" top="10" />
    </s:TitleWindow>
 
    <s:TitleWindow id="tw2"
                   title="Spark TitleWindow with control bar"
                   controlBarVisible="true"
                   width="280" height="120"
                   horizontalCenter="0" verticalCenter="0">
        <s:controlBarContent>
            <s:Label text="Control bar content" />
        </s:controlBarContent>
        <s:Label text="Spark TitleWindow contents" left="10" top="10" />
    </s:TitleWindow>
 
</s:Application>

Or you can se the cornerRadius style using ActionScript, as seen in the following example:

<?xml version="1.0" encoding="utf-8"?>
<!-- http://blog.flexexamples.com/2010/04/27/setting-the-corner-radius-on-the-spark-titlewindow-container-in-flex-4/ -->
<s:Application name="Spark_TitleWindow_cornerRadius_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:layout>
        <s:HorizontalLayout horizontalAlign="center" verticalAlign="middle" />
    </s:layout>
    <s:controlBarContent>
        <s:Label text="cornerRadius:" />
        <s:HSlider id="sl" maximum="15" change="sl_changeHandler(event);" />
    </s:controlBarContent>
 
    <fx:Script>
        <![CDATA[
            protected function sl_changeHandler(evt:Event):void {
                tw1.setStyle("cornerRadius", sl.value);
                tw2.setStyle("cornerRadius", sl.value);
            }
        ]]>
    </fx:Script>
 
    <s:TitleWindow id="tw1"
                   title="Spark TitleWindow without control bar"
                   controlBarVisible="true"
                   width="280" height="120"
                   horizontalCenter="0" verticalCenter="0">
        <s:Label text="Spark TitleWindow contents" left="10" top="10" />
    </s:TitleWindow>
 
    <s:TitleWindow id="tw2"
                   title="Spark TitleWindow with control bar"
                   controlBarVisible="true"
                   width="280" height="120"
                   horizontalCenter="0" verticalCenter="0">
        <s:controlBarContent>
            <s:Label text="Control bar content" />
        </s:controlBarContent>
        <s:Label text="Spark TitleWindow contents" left="10" top="10" />
    </s:TitleWindow>
 
</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.


Viewing all articles
Browse latest Browse all 10

Trending Articles