<?xml version="1.0" encoding="UTF-8"?><!-- generator="wordpress/2.2.1" -->
<rss version="2.0" 
	xmlns:content="http://purl.org/rss/1.0/modules/content/">
<channel>
	<title>Comments on: Rotating images using the Matrix class</title>
	<link>http://blog.flexexamples.com/2007/09/14/rotating-images-using-the-matrix-class/</link>
	<description>A bunch of examples for Adobe Flex and ActionScript</description>
	<pubDate>Fri, 05 Dec 2008 09:42:17 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.2.1</generator>

	<item>
		<title>By: Anonymous</title>
		<link>http://blog.flexexamples.com/2007/09/14/rotating-images-using-the-matrix-class/#comment-14793</link>
		<author>Anonymous</author>
		<pubDate>Tue, 19 Aug 2008 09:51:21 +0000</pubDate>
		<guid>http://blog.flexexamples.com/2007/09/14/rotating-images-using-the-matrix-class/#comment-14793</guid>
		<description>private function transformImage(img:Image, x:Number, y:Number, angle:Number):void {				

	var offsetWidth:Number = img.contentWidth / 2 ;
	var offsetHeight:Number = img.contentHeight / 2 ;

	var sin=Math.sin(angle);
	var cos=Math.cos(angle);

	var tempMatrix:Matrix = new Matrix();

	tempMatrix.a = cos;
	tempMatrix.b = -sin;
	tempMatrix.c = sin;
	tempMatrix.d = cos;

	tempMatrix.tx = x - cos * offsetWidth - sin * offsetHeight + offsetWidth;
	tempMatrix.ty = y + sin * offsetWidth - cos * offsetHeight + offsetHeight;

	img.transform.matrix = tempMatrix;</description>
		<content:encoded><![CDATA[<p>private function transformImage(img:Image, x:Number, y:Number, angle:Number):void {				</p>
<p>	var offsetWidth:Number = img.contentWidth / 2 ;<br />
	var offsetHeight:Number = img.contentHeight / 2 ;</p>
<p>	var sin=Math.sin(angle);<br />
	var cos=Math.cos(angle);</p>
<p>	var tempMatrix:Matrix = new Matrix();</p>
<p>	tempMatrix.a = cos;<br />
	tempMatrix.b = -sin;<br />
	tempMatrix.c = sin;<br />
	tempMatrix.d = cos;</p>
<p>	tempMatrix.tx = x - cos * offsetWidth - sin * offsetHeight + offsetWidth;<br />
	tempMatrix.ty = y + sin * offsetWidth - cos * offsetHeight + offsetHeight;</p>
<p>	img.transform.matrix = tempMatrix;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Adam</title>
		<link>http://blog.flexexamples.com/2007/09/14/rotating-images-using-the-matrix-class/#comment-12110</link>
		<author>Adam</author>
		<pubDate>Sat, 19 Apr 2008 07:37:37 +0000</pubDate>
		<guid>http://blog.flexexamples.com/2007/09/14/rotating-images-using-the-matrix-class/#comment-12110</guid>
		<description>Can someone please explain to why the image needs to be in a VBox? This makes no sense to me.</description>
		<content:encoded><![CDATA[<p>Can someone please explain to why the image needs to be in a VBox? This makes no sense to me.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Karl Garske</title>
		<link>http://blog.flexexamples.com/2007/09/14/rotating-images-using-the-matrix-class/#comment-7297</link>
		<author>Karl Garske</author>
		<pubDate>Sun, 02 Mar 2008 23:10:12 +0000</pubDate>
		<guid>http://blog.flexexamples.com/2007/09/14/rotating-images-using-the-matrix-class/#comment-7297</guid>
		<description>Man, I got worked trying to integrate this into my own application. If the the Image is not the only thing included in the VBox, this example no longer behaves as advertised. Seems that the matrix is relative to whatever container the Image resides in, not the Image itself. Just making sure this is clear to others who are still new to this stuff.</description>
		<content:encoded><![CDATA[<p>Man, I got worked trying to integrate this into my own application. If the the Image is not the only thing included in the VBox, this example no longer behaves as advertised. Seems that the matrix is relative to whatever container the Image resides in, not the Image itself. Just making sure this is clear to others who are still new to this stuff.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Alexander Rose</title>
		<link>http://blog.flexexamples.com/2007/09/14/rotating-images-using-the-matrix-class/#comment-5641</link>
		<author>Alexander Rose</author>
		<pubDate>Mon, 31 Dec 2007 01:02:44 +0000</pubDate>
		<guid>http://blog.flexexamples.com/2007/09/14/rotating-images-using-the-matrix-class/#comment-5641</guid>
		<description>Is it okay to use this on my own site? I'm happy to link back to you from my new site which I hope to have running by the end of January. Happy New Year to you, I hope it's a good one!</description>
		<content:encoded><![CDATA[<p>Is it okay to use this on my own site? I&#8217;m happy to link back to you from my new site which I hope to have running by the end of January. Happy New Year to you, I hope it&#8217;s a good one!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Rob Cannon</title>
		<link>http://blog.flexexamples.com/2007/09/14/rotating-images-using-the-matrix-class/#comment-4837</link>
		<author>Rob Cannon</author>
		<pubDate>Thu, 06 Dec 2007 22:37:30 +0000</pubDate>
		<guid>http://blog.flexexamples.com/2007/09/14/rotating-images-using-the-matrix-class/#comment-4837</guid>
		<description>If you examine the example carefully, it doesn't rotate consistently around the exact center of the image.  And then, if you go through an entire 360 degrees, the image position will be about 10 pixels or so below where it started.

Using absolute positioning, try this function below instead.  You have to pass the original x and y of the image control, don't use the .x or .y properties since they change when the image is transformed.

&lt;pre class="code"&gt;
private function transformImage(img:Image, x:Number, y:Number, angle:Number):void {				
	
	var offsetWidth:Number = img.contentWidth / 2 ;
	var offsetHeight:Number = img.contentHeight / 2 ;
	
	var sin=Math.sin(angle);
	var cos=Math.cos(angle);
	
	var tempMatrix:Matrix = new Matrix();
	
	tempMatrix.a = cos;
	tempMatrix.b = -sin;
	tempMatrix.c = sin;
	tempMatrix.d = cos;
	
	tempMatrix.tx = x - cos * offsetWidth - sin * offsetHeight \+ offsetWidth;
	tempMatrix.ty = y \+ sin * offsetWidth - cos * offsetHeight \+ offsetHeight;
	
	img.transform.matrix = tempMatrix;
	
}
&lt;/pre&gt;</description>
		<content:encoded><![CDATA[<p>If you examine the example carefully, it doesn&#8217;t rotate consistently around the exact center of the image.  And then, if you go through an entire 360 degrees, the image position will be about 10 pixels or so below where it started.</p>
<p>Using absolute positioning, try this function below instead.  You have to pass the original x and y of the image control, don&#8217;t use the .x or .y properties since they change when the image is transformed.</p>
<pre class="code">
private function transformImage(img:Image, x:Number, y:Number, angle:Number):void {				

	var offsetWidth:Number = img.contentWidth / 2 ;
	var offsetHeight:Number = img.contentHeight / 2 ;

	var sin=Math.sin(angle);
	var cos=Math.cos(angle);

	var tempMatrix:Matrix = new Matrix();

	tempMatrix.a = cos;
	tempMatrix.b = -sin;
	tempMatrix.c = sin;
	tempMatrix.d = cos;

	tempMatrix.tx = x - cos * offsetWidth - sin * offsetHeight + offsetWidth;
	tempMatrix.ty = y + sin * offsetWidth - cos * offsetHeight + offsetHeight;

	img.transform.matrix = tempMatrix;

}
</pre>
]]></content:encoded>
	</item>
	<item>
		<title>By: chas</title>
		<link>http://blog.flexexamples.com/2007/09/14/rotating-images-using-the-matrix-class/#comment-4098</link>
		<author>chas</author>
		<pubDate>Mon, 12 Nov 2007 20:52:41 +0000</pubDate>
		<guid>http://blog.flexexamples.com/2007/09/14/rotating-images-using-the-matrix-class/#comment-4098</guid>
		<description>beautiful!  thank you, thank you, searched entire web for this and this is the only working example in all of googleland.  thanks!

c</description>
		<content:encoded><![CDATA[<p>beautiful!  thank you, thank you, searched entire web for this and this is the only working example in all of googleland.  thanks!</p>
<p>c</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ravindra Nath Chowdary</title>
		<link>http://blog.flexexamples.com/2007/09/14/rotating-images-using-the-matrix-class/#comment-3730</link>
		<author>Ravindra Nath Chowdary</author>
		<pubDate>Tue, 30 Oct 2007 10:20:35 +0000</pubDate>
		<guid>http://blog.flexexamples.com/2007/09/14/rotating-images-using-the-matrix-class/#comment-3730</guid>
		<description>This is fine</description>
		<content:encoded><![CDATA[<p>This is fine</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Joe Corner Reeve</title>
		<link>http://blog.flexexamples.com/2007/09/14/rotating-images-using-the-matrix-class/#comment-2685</link>
		<author>Joe Corner Reeve</author>
		<pubDate>Thu, 20 Sep 2007 20:10:51 +0000</pubDate>
		<guid>http://blog.flexexamples.com/2007/09/14/rotating-images-using-the-matrix-class/#comment-2685</guid>
		<description>Hello I have Problem :(

I want to leave this image on the position. an image will to rotate automacally.
I see that mxml, why do you not use with ? I am ztying with problem of rotating image. :(

Thanks Joe Corner Reeve</description>
		<content:encoded><![CDATA[<p>Hello I have Problem :(</p>
<p>I want to leave this image on the position. an image will to rotate automacally.<br />
I see that mxml, why do you not use with ? I am ztying with problem of rotating image. :(</p>
<p>Thanks Joe Corner Reeve</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: peterd</title>
		<link>http://blog.flexexamples.com/2007/09/14/rotating-images-using-the-matrix-class/#comment-2138</link>
		<author>peterd</author>
		<pubDate>Fri, 14 Sep 2007 23:06:22 +0000</pubDate>
		<guid>http://blog.flexexamples.com/2007/09/14/rotating-images-using-the-matrix-class/#comment-2138</guid>
		<description>Flanture,

Thanks, good catch! Another case of me forgetting to web-friendly the MXML code after posting it in the Interwebs.

Example updated above and should hopefully work now. I'll try and get View Source-able SWFs posted later this evening.

Peter</description>
		<content:encoded><![CDATA[<p>Flanture,</p>
<p>Thanks, good catch! Another case of me forgetting to web-friendly the MXML code after posting it in the Interwebs.</p>
<p>Example updated above and should hopefully work now. I&#8217;ll try and get View Source-able SWFs posted later this evening.</p>
<p>Peter</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Flanture</title>
		<link>http://blog.flexexamples.com/2007/09/14/rotating-images-using-the-matrix-class/#comment-2137</link>
		<author>Flanture</author>
		<pubDate>Fri, 14 Sep 2007 23:01:41 +0000</pubDate>
		<guid>http://blog.flexexamples.com/2007/09/14/rotating-images-using-the-matrix-class/#comment-2137</guid>
		<description>This line doesn't work for me:
°

But this does:
{String.fromCharCode(176)}

Good example.</description>
		<content:encoded><![CDATA[<p>This line doesn&#8217;t work for me:<br />
°</p>
<p>But this does:<br />
{String.fromCharCode(176)}</p>
<p>Good example.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
