The following example shows how you can skew a Flex Image control vertically and horizontally using the Transform and Matrix classes.

Full code after the jump.

View MXML

<?xml version="1.0" encoding="utf-8"?>
<!-- http://blog.flexexamples.com/2008/04/07/skewing-an-image-control-in-flex/ -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
        layout="vertical"
        verticalAlign="middle"
        backgroundColor="white">

    <mx:Script>
        <![CDATA[
            private function radiansToDegrees(radians:Number):Number {
                return (radians * (180 / Math.PI));
            }

            private function degreesToRadians(degrees:Number):Number {
                return (degrees * (Math.PI / 180));
            }

            private function skewr(target:DisplayObject):void {
                var m:Matrix = target.transform.matrix;
                m.b = Math.tan(degreesToRadians(sliderY.value));
                m.c = Math.tan(degreesToRadians(sliderX.value));

                var t:Transform = new Transform(target);
                t.matrix = m;

                target.transform = t;
            }

            private function resetMatrix(target:DisplayObject):void {
                // Reset sliders.
                sliderX.value = 0;
                sliderY.value = 0;
                skewr(target);
            }
        ]]>
    </mx:Script>

    <mx:ApplicationControlBar dock="true">
        <mx:Form styleName="plain">
            <mx:FormItem label="skew X:">
                <mx:HSlider id="sliderX"
                        minimum="-15"
                        maximum="15"
                        value="0"
                        liveDragging="true"
                        snapInterval="1"
                        change="skewr(image);" />
            </mx:FormItem>
            <mx:FormItem label="skew Y:">
                <mx:HSlider id="sliderY"
                        minimum="-15"
                        maximum="15"
                        value="0"
                        liveDragging="true"
                        snapInterval="1"
                        change="skewr(image);" />
            </mx:FormItem>
            <mx:FormItem>
                <mx:Button label="Reset"
                        click="resetMatrix(image);" />
            </mx:FormItem>
        </mx:Form>
    </mx:ApplicationControlBar>

    <mx:Image id="image"
            source="@Embed('Fx.png')"
            scaleContent="true"
            maintainAspectRatio="true"
            width="200"
            height="200" />

</mx:Application>

View source is enabled in the following example.

 
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.

2 Responses to Skewing an Image control in Flex

  1. Gonzalo says:

    why this is tagged with DateChooser?

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