Setting the joint style on a Path stroke in Flex 4

The following example shows how you can set the joint style on a Flex 4 SolidColorStroke object by setting the joints property to a static constant in the JointStyle class (flash.display.JointStyle).

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/2009/01/09/setting-the-joint-style-on-a-path-stroke-in-flex-gumbo/ -->
<s:Application name="Spark_Path_stroke_joints_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">
 
    <fx:Declarations>
        <fx:String id="pathData">M 0 0 L 200 0 L 0 80 Z</fx:String>
    </fx:Declarations>
 
    <s:controlBarContent>
        <mx:Form>
            <mx:FormItem label="joints:">
                <s:DropDownList id="comboBox" requireSelection="true">
                    <s:dataProvider>
                        <s:ArrayList source="[bevel,miter,round]" />
                    </s:dataProvider>
                </s:DropDownList>
            </mx:FormItem>
        </mx:Form>
    </s:controlBarContent>
 
    <s:Group horizontalCenter="0" verticalCenter="0">
        <s:Path id="path" data="{pathData}">
            <s:stroke>
                <s:SolidColorStroke id="pathStroke"
                        joints="{comboBox.selectedItem}"
                        color="red"
                        weight="40" />
            </s:stroke>
        </s:Path>
        <s:Path data="{pathData}">
            <s:stroke>
                <s:SolidColorStroke color="black" weight="1" />
            </s:stroke>
        </s:Path>
    </s:Group>
 
</s:Application>

[GoogleAdsWide]

View source is enabled in the following example.

You can also set the joints property using ActionScript, as seen in the following example:

<?xml version="1.0" encoding="utf-8"?>
<!-- http://blog.flexexamples.com/2009/01/09/setting-the-joint-style-on-a-path-stroke-in-flex-gumbo/ -->
<s:Application name="Spark_Path_stroke_joints_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="joints:">
                <s:DropDownList id="comboBox"
                        selectedIndex="2"
                        change="comboBox_change(event);">
                    <s:dataProvider>
                        <s:ArrayList>
                            <s:source>
                                <fx:String>{JointStyle.BEVEL}</fx:String>
                                <fx:String>{JointStyle.MITER}</fx:String>
                                <fx:String>{JointStyle.ROUND}</fx:String>
                            </s:source>
                        </s:ArrayList>
                    </s:dataProvider>
                </s:DropDownList>
            </mx:FormItem>
        </mx:Form>
    </s:controlBarContent>
 
    <fx:Script>
        <![CDATA[
            import mx.events.ListEvent;
            import spark.events.IndexChangeEvent;
 
            protected function comboBox_change(evt:IndexChangeEvent):void {
                pathStroke.joints = comboBox.selectedItem.toString();
            }
        ]]>
    </fx:Script>
 
    <fx:Declarations>
        <fx:String id="pathData">M 0 0 L 200 0 L 0 80 Z</fx:String>
    </fx:Declarations>
 
    <s:Graphic horizontalCenter="0" verticalCenter="0">
        <s:Path id="path" data="{pathData}">
            <s:stroke>
                <s:SolidColorStroke id="pathStroke"
                        color="red"
                        weight="40" />
            </s:stroke>
        </s:Path>
        <s:Path data="{pathData}">
            <s:stroke>
                <s:SolidColorStroke color="black" weight="1" />
            </s:stroke>
        </s:Path>
    </s:Graphic>
 
</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 joint style on a Path stroke in Flex 4

Comments are closed.