<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Flex Examples &#187; Matrix</title>
	<atom:link href="http://blog.flexexamples.com/category/matrix/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.flexexamples.com</link>
	<description>Just a bunch of Adobe Flex Examples</description>
	<lastBuildDate>Wed, 26 Jan 2011 18:09:51 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Skewing an Image control in Flex</title>
		<link>http://blog.flexexamples.com/2008/04/07/skewing-an-image-control-in-flex/</link>
		<comments>http://blog.flexexamples.com/2008/04/07/skewing-an-image-control-in-flex/#comments</comments>
		<pubDate>Tue, 08 Apr 2008 06:57:34 +0000</pubDate>
		<dc:creator>Peter deHaan</dc:creator>
				<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[Image]]></category>
		<category><![CDATA[Matrix]]></category>
		<category><![CDATA[transform]]></category>

		<guid isPermaLink="false">http://blog.flexexamples.com/2008/04/07/skewing-an-image-control-in-flex/</guid>
		<description><![CDATA[<p>The following example shows how you can skew a Flex Image control vertically and horizontally using the Transform and Matrix classes.</p> <p>Full code after the jump.</p> <p></p> <p class="download"><a href="http://blog.flexexamples.com/wp-content/uploads/Image_transform_test/bin/srcview/source/main.mxml.html">View MXML</a></p> &#60;?xml version="1.0" encoding="utf-8"?&#62; &#60;!-- http://blog.flexexamples.com/2008/04/07/skewing-an-image-control-in-flex/ --&#62; &#60;mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical" verticalAlign="middle" backgroundColor="white"&#62; &#60;mx:Script&#62; &#60;![CDATA[ private function radiansToDegrees(radians:Number):Number { return (radians * (180 / Math.PI)); } [...]]]></description>
			<content:encoded><![CDATA[<p>The following example shows how you can skew a Flex Image control vertically and horizontally using the Transform and Matrix classes.</p>
<p>Full code after the jump.</p>
<p><span id="more-582"></span></p>
<p class="download"><a href="http://blog.flexexamples.com/wp-content/uploads/Image_transform_test/bin/srcview/source/main.mxml.html">View MXML</a></p>
<pre class="code">
&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;!-- http://blog.flexexamples.com/2008/04/07/skewing-an-image-control-in-flex/ --&gt;
&lt;mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
        layout="vertical"
        verticalAlign="middle"
        backgroundColor="white"&gt;

    &lt;mx:Script&gt;
        &lt;![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);
            }
        ]]&gt;
    &lt;/mx:Script&gt;

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

    &lt;mx:Image id="image"
            source="@Embed('Fx.png')"
            scaleContent="true"
            maintainAspectRatio="true"
            width="200"
            height="200" /&gt;

&lt;/mx:Application&gt;
</pre>
<p class="information"><a href="http://blog.flexexamples.com/wp-content/uploads/Image_transform_test/bin/srcview/index.html">View source</a> is enabled in the following example.</p>
<p><iframe src="http://blog.flexexamples.com/wp-content/uploads/Image_transform_test/bin/main.html" width="100%" height="400"></iframe></p>
<div class="evernoteSiteMemory"><a href="javascript:" onclick="Evernote.doClip({title: 'Skewing an Image control in Flex on FlexExamples.com',url: 'http://blog.flexexamples.com/2008/04/07/skewing-an-image-control-in-flex/',contentID: 'post-582',code: 'Pete9667',suggestNotebook: 'FlexExamples',suggestTags: 'transform',providerName: 'FlexExamples.com',styling: 'text' });return false" class="evernoteSiteMemoryLink"><img src="http://static.evernote.com/article-clipper-remember.png" class="evernoteSiteMemoryButton" />
				</a>				<div class="evernoteSiteMemoryClear">&nbsp;</div>
</div>]]></content:encoded>
			<wfw:commentRss>http://blog.flexexamples.com/2008/04/07/skewing-an-image-control-in-flex/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Rotating images using the Matrix class</title>
		<link>http://blog.flexexamples.com/2007/09/14/rotating-images-using-the-matrix-class/</link>
		<comments>http://blog.flexexamples.com/2007/09/14/rotating-images-using-the-matrix-class/#comments</comments>
		<pubDate>Fri, 14 Sep 2007 18:29:40 +0000</pubDate>
		<dc:creator>Peter deHaan</dc:creator>
				<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[Matrix]]></category>
		<category><![CDATA[Rotate]]></category>
		<category><![CDATA[concat()]]></category>
		<category><![CDATA[transform]]></category>
		<category><![CDATA[translate()]]></category>

		<guid isPermaLink="false">http://blog.flexexamples.com/2007/09/14/rotating-images-using-the-matrix-class/</guid>
		<description><![CDATA[<p>Somebody recently asked on a forum how you could rotate images using the Matrix class. I quickly built this super-simple little example which shows how to use the &#60;mx:Rotate /&#62; effect as well as the Matrix class&#8217;s rotate() method.</p> <p>Full code after the jump.</p> <p></p> <p>If you&#8217;re new to transforms and matrices, check out Senocular.com&#8217;s [...]]]></description>
			<content:encoded><![CDATA[<p>Somebody recently asked on a forum how you could rotate images using the Matrix class. I quickly built this super-simple little example which shows how to use the &lt;mx:Rotate /&gt; effect as well as the Matrix class&#8217;s <code>rotate()</code> method.</p>
<p>Full code after the jump.</p>
<p><span id="more-180"></span></p>
<p>If you&#8217;re new to transforms and matrices, check out Senocular.com&#8217;s excellent article, &#8220;<a href="http://www.senocular.com/flash/tutorials/transformmatrix/">Understanding the Transform Matrix in Flash 8</a>&#8220;.</p>
<p class="download"><a href="http://blog.flexexamples.com/wp-content/uploads/Matrix_rotate_test/main.mxml">View MXML</a></p>
<pre class="code">
&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;!-- http://blog.flexexamples.com/2007/09/14/rotating-images-using-the-matrix-class/ --&gt;
&lt;mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
        layout="horizontal"
        verticalAlign="middle"
        backgroundColor="white"&gt;

    &lt;mx:String id="deg"&gt;&amp;#0176;&lt;/mx:String&gt;

    &lt;mx:Script&gt;
        &lt;![CDATA[
            import mx.core.UIComponent;

            private function img1_effectEnd():void {
                /* Set the appropriate Label text. */
                lbl1.text = "img1.rotation = " + img1.rotation.toString() + deg;
            }

            private function img2_creationComplete():void {
                /* "Copy" the existing matrix. */
                var m1:Matrix = img2.transform.matrix;
                /* Rotate the matrix 45 degrees (note that we have to
                   convert from degrees to radians since the rotate()
                   method expects radians. */
                m1.rotate(degreesToRadians(45));
                /* Concatenate the original matrix onto the rotated
                   matrix so we don't lose the original X and Y
                   coordinates and any other effects. */
                m1.concat(img2.transform.matrix);
                /* "Copy" the new matrix over the existing matrix. */
                img2.transform.matrix = m1;
                /* Set the appropriate Label text. */
                lbl2.text = "img2.rotation = " + img2.rotation.toString() + deg;
            }

            private function img_rollOver(cTarget:UIComponent):void {
                cTarget.toolTip = cTarget.name + ".rotation = " + cTarget.rotation.toString();
            }

            private function radiansToDegrees(radians:Number):Number {
                var degrees:Number = radians * (180 / Math.PI);
                return degrees;
            }

            private function degreesToRadians(degrees:Number):Number {
                var radians:Number = degrees * (Math.PI / 180);
                return radians;
            }
        ]]&gt;
    &lt;/mx:Script&gt;

    &lt;mx:Rotate id="rotate" angleFrom="0" angleTo="45" duration="1" /&gt;

    &lt;mx:ApplicationControlBar dock="true"&gt;
        &lt;mx:Label id="lbl1" /&gt;
        &lt;mx:Spacer width="50" /&gt;
        &lt;mx:Label id="lbl2" /&gt;
    &lt;/mx:ApplicationControlBar&gt;

    &lt;mx:Image id="img1"
            source="http://www.helpexamples.com/flash/images/logo.png"
            creationCompleteEffect="{rotate}"
            effectEnd="img1_effectEnd();"
            rollOver="img_rollOver(UIComponent(event.currentTarget));" /&gt;

    &lt;mx:Spacer width="50" /&gt;

    &lt;mx:Image id="img2"
            source="http://www.helpexamples.com/flash/images/logo.png"
            creationComplete="img2_creationComplete();"
            rollOver="img_rollOver(UIComponent(event.currentTarget));" /&gt;

&lt;/mx:Application&gt;
</pre>
<p class="information"><a href="http://blog.flexexamples.com/wp-content/uploads/Matrix_rotate_test/bin/srcview/index.html">View source</a> is enabled in the following example.</p>
<p><iframe src="http://blog.flexexamples.com/wp-content/uploads/Matrix_rotate_test/bin/main.html" width="100%" height="200"></iframe></p>
<p>And just for giggles, here is a similar example which lets you rotate the image using a couple of Button controls. Note that the rotation is done around the center point of the image by calling the Matrix class&#8217;s <code>translate()</code> method to move the image before and after the rotation.</p>
<p class="download"><a href="http://blog.flexexamples.com/wp-content/uploads/Matrix_rotate_test_2/main.mxml">View MXML</a></p>
<pre class="code">
&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;!-- http://blog.flexexamples.com/2007/09/14/rotating-images-using-the-matrix-class/ --&gt;
&lt;mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
        layout="vertical"
        verticalAlign="middle"
        backgroundColor="white"&gt;

    &lt;mx:Script&gt;
        &lt;![CDATA[
            private function button_click(evt:Event):void {
                var direction:int;
                switch (evt.currentTarget) {
                    case degreesUp:
                        direction = +1;
                        break;
                    case degreesDown:
                        direction = -1;
                        break;
                }

                var radians:Number = degreesToRadians(direction);
                var offsetWidth:Number = img.width / 2;
                var offsetHeight:Number = img.height / 2;
                var tempMatrix:Matrix = img.transform.matrix;
                tempMatrix.translate(-offsetWidth, -offsetHeight);
                tempMatrix.rotate(radians);
                tempMatrix.translate(+offsetWidth, +offsetHeight);

                img.transform.matrix = tempMatrix;

                rotateDeg = img.rotation;
            }

            private function radiansToDegrees(radians:Number):Number {
                var degrees:Number = radians * (180 / Math.PI);
                return degrees;
            }

            private function degreesToRadians(degrees:Number):Number {
                var radians:Number = degrees * (Math.PI / 180);
                return radians;
            }
        ]]&gt;
    &lt;/mx:Script&gt;

    &lt;mx:Number id="rotateDeg"&gt;0&lt;/mx:Number&gt;
    &lt;mx:NumberFormatter id="numberFormatter" precision="0" /&gt;
    &lt;mx:String id="deg"&gt;{String.fromCharCode(176)}&lt;/mx:String&gt;

    &lt;mx:ApplicationControlBar dock="true"&gt;
        &lt;mx:Label text="rotation:" /&gt;
        &lt;mx:Button id="degreesUp"
                label="+"
                autoRepeat="true"
                click="button_click(event);"
                buttonDown="button_click(event);" /&gt;
        &lt;mx:Button id="degreesDown"
                label="-"
                autoRepeat="true"
                click="button_click(event);"
                buttonDown="button_click(event);" /&gt;
        &lt;mx:Spacer width="50" /&gt;
        &lt;mx:Label id="lbl"
                text="{numberFormatter.format(rotateDeg)}{deg}" /&gt;
    &lt;/mx:ApplicationControlBar&gt;

    &lt;mx:VBox&gt;
        &lt;mx:Image id="img"
                source="http://www.helpexamples.com/flash/images/logo.png" /&gt;
    &lt;/mx:VBox&gt;

&lt;/mx:Application&gt;
</pre>
<p class="information"><a href="http://blog.flexexamples.com/wp-content/uploads/Matrix_rotate_test_2/bin/srcview/index.html">View source</a> is enabled in the following example.</p>
<p><iframe src="http://blog.flexexamples.com/wp-content/uploads/Matrix_rotate_test_2/bin/main.html" width="100%" height="250"></iframe></p>
<div class="evernoteSiteMemory"><a href="javascript:" onclick="Evernote.doClip({title: 'Rotating images using the Matrix class on FlexExamples.com',url: 'http://blog.flexexamples.com/2007/09/14/rotating-images-using-the-matrix-class/',contentID: 'post-180',code: 'Pete9667',suggestNotebook: 'FlexExamples',suggestTags: 'concat(),transform,translate()',providerName: 'FlexExamples.com',styling: 'text' });return false" class="evernoteSiteMemoryLink"><img src="http://static.evernote.com/article-clipper-remember.png" class="evernoteSiteMemoryButton" />
				</a>				<div class="evernoteSiteMemoryClear">&nbsp;</div>
</div>]]></content:encoded>
			<wfw:commentRss>http://blog.flexexamples.com/2007/09/14/rotating-images-using-the-matrix-class/feed/</wfw:commentRss>
		<slash:comments>23</slash:comments>
		</item>
	</channel>
</rss>

