The following example shows how you can set an Ellipse object’s stroke weight by setting the weight property on the SolidColorStroke object.

Full code after the jump.

To use the following code, you must have Flash Player 10 and a Flex Gumbo SDK installed in your Flex Builder 3. For more information on downloading and installing the Gumbo SDK into Flex Builder 3, see “Using the beta Gumbo SDK in Flex Builder 3″.

View MXML

<?xml version="1.0" encoding="utf-8"?>
<!-- http://blog.flexexamples.com/2008/11/28/setting-the-thickness-of-a-stroke-on-an-ellipse-in-flex-gumbo/ -->
<FxApplication name="SolidColorStroke_weight_test"
        xmlns="http://ns.adobe.com/mxml/2009">
    <layout>
        <BasicLayout />
    </layout>

    <Form>
        <FormItem label="weight:">
            <HSlider id="slider"
                    minimum="0"
                    maximum="20"
                    value="0"
                    snapInterval="1"
                    tickInterval="1"
                    liveDragging="true" />
        </FormItem>
    </Form>

    <Ellipse id="ellipse"
            width="300"
            height="200"
            horizontalCenter="0"
            verticalCenter="0">
        <stroke>
            <SolidColorStroke id="stroke"
                    weight="{slider.value}" />
        </stroke>
    </Ellipse>

</FxApplication>

View source is enabled in the following example.

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

View MXML

<?xml version="1.0" encoding="utf-8"?>
<!-- http://blog.flexexamples.com/2008/11/28/setting-the-thickness-of-a-stroke-on-an-ellipse-in-flex-gumbo/ -->
<FxApplication name="SolidColorStroke_weight_test"
        xmlns="http://ns.adobe.com/mxml/2009">
    <layout>
        <BasicLayout />
    </layout>

    <Script>
        <![CDATA[
            import mx.events.SliderEvent;

            private function slider_change(evt:SliderEvent):void {
                stroke.weight = evt.value;
            }
        ]]>
    </Script>

    <Form>
        <FormItem label="weight:">
            <HSlider id="slider"
                    minimum="0"
                    maximum="20"
                    value="0"
                    snapInterval="1"
                    tickInterval="1"
                    liveDragging="true"
                    change="slider_change(event);" />
        </FormItem>
    </Form>

    <Ellipse id="ellipse"
            width="300"
            height="200"
            horizontalCenter="0"
            verticalCenter="0">
        <stroke>
            <SolidColorStroke id="stroke" />
        </stroke>
    </Ellipse>

</FxApplication>

Due to popular demand, here is the “same” example in a more ActionScript friendly format:

View MXML

<?xml version="1.0" encoding="utf-8"?>
<!-- http://blog.flexexamples.com/2008/11/28/setting-the-thickness-of-a-stroke-on-an-ellipse-in-flex-gumbo/ -->
<FxApplication name="SolidColorStroke_weight_test"
        xmlns="http://ns.adobe.com/mxml/2009"
        initialize="init();">
    <layout>
        <BasicLayout />
    </layout>

    <Script>
        <![CDATA[
            import mx.containers.Form;
            import mx.containers.FormItem;
            import mx.controls.HSlider;
            import mx.events.SliderEvent;
            import mx.graphics.Ellipse;
            import mx.graphics.SolidColorStroke;

            private var slider:HSlider;
            private var ellipse:Ellipse;

            private function init():void {
                slider = new HSlider();
                slider.minimum = 0;
                slider.maximum = 20;
                slider.value = 0;
                slider.snapInterval = 1;
                slider.tickInterval = 1;
                slider.liveDragging = true;
                slider.addEventListener(SliderEvent.CHANGE, slider_change);

                var formItem:FormItem = new FormItem();
                formItem.label = "weight:";
                formItem.addChild(slider);

                var form:Form = new Form();
                form.addChild(formItem);
                addItem(form);

                ellipse = new Ellipse();
                ellipse.stroke = new SolidColorStroke();
                ellipse.width = 300;
                ellipse.height = 200;
                ellipse.horizontalCenter = 0;
                ellipse.verticalCenter = 0;
                addItem(ellipse);
            }

            private function slider_change(evt:SliderEvent):void {
                ellipse.stroke.weight = evt.value;
            }
        ]]>
    </Script>

</FxApplication>

This entry is based on a beta version of the Flex Gumbo 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 Gumbo SDK.

 
Tagged with:
 
About The Author

Peter deHaan

Peter deHaan currently works for Adobe on the Flex SDK QA team. While not working on Flex, Flash, and ColdFusion applications, Peter enjoys making up bios and writing in 3rd person. Peter's rarely updated blog can be found at blogs.adobe.com/pdehaan/, actionscriptexamples.com, airexamples.com, and coldfusionexamples.com.

One Response to Setting the thickness of a stroke on an Ellipse in Flex Gumbo

  1. Estrella says:

    Solid example. I’ve been looking for a piece of code like this for awhile, thanks!

Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="">

Anti-Spam Protection by WP-SpamFree