{"id":7,"date":"2010-08-20T17:30:00","date_gmt":"2010-08-20T17:30:00","guid":{"rendered":"http:\/\/subashselvaraj.com\/?p=7"},"modified":"2025-06-21T07:14:48","modified_gmt":"2025-06-21T07:14:48","slug":"rotate-around-center-flexas3","status":"publish","type":"post","link":"https:\/\/subashselvaraj.com\/index.php\/2010\/08\/20\/rotate-around-center-flexas3\/","title":{"rendered":"Rotate around center Flex\/AS3"},"content":{"rendered":"<div dir=\"ltr\" style=\"text-align: left;\">\n<p><span style=\"font-family: Helvetica Neue, Arial, Helvetica, sans-serif;\">I have been searching for rotating any display object based on its center and ended up with the stuffs using MatrixTransformer.<\/span><br \/>\n<span style=\"font-family: Helvetica Neue, Arial, Helvetica, sans-serif;\"><br \/>\n<\/span><span style=\"font-family: Helvetica Neue, Arial, Helvetica, sans-serif;\">Though it may helpful to use those stuffs, it didnt work for me. finally i did a work around it and created a method which uses the getRect() of AS3 and works well without the MatrixTransformer stuff. I have posted that function here and it will be helpful for some one.<\/span><\/p>\n<pre class=\"brush:as3\">\/**\n* Rotates the object based on its center\n* Parameters: @obj =&gt; the object to rotate\n* @ rotation =&gt; angle to rotate\n* *\/\npublic function RotateAroundCenter(obj:Object, rotation:Number):void\n   {\n\t\tvar bound:Rectangle = new Rectangle();\n\t\t\/\/ get the bounded rectangle of objects\n\t\tbound = obj.getRect(this);\n\n\t\t\/\/ calculate mid poits\n\t\tvar midx1:Number = bound.x + bound.width\/2;\n\t\tvar midy1:Number = bound.y + bound.height\/2;\n\n\t\t\/\/ assign the rotation\n\t\tobj.rotation = rotation;\n\n\t\t\/\/ assign the previous mid point as (x,y)\n\t\tobj.x = midx1;\n\t\tobj.y = midy1;\n\n\t\t\/\/ get the new bounded rectangle of objects\n\t\tbound = obj.getRect(this);\n\n\t\t\/\/ calculate new mid points\n\t\tvar midx2:Number = bound.x + bound.width\/2;\n\t\tvar midy2:Number = bound.y + bound.height\/2;\n\n\t\t\/\/ calculate differnece between the current mid and (x,y) and subtract\n\t\t\/\/it to position the object in the previous bound.\n\t\tvar diff:Number = midx2 - obj.x;\n\t\tobj.x -= diff;\n\t\tdiff = midy2 - obj.y;\n\t\tobj.y -= diff;\n}\n\n<\/pre>\n<p><span style=\"font-family: Helvetica Neue, Arial, Helvetica, sans-serif;\">you can use the above function as described below,<\/span><\/p>\n<pre class=\"brush:as3\">var img:Canvas = new Canvas()\nRotateAroundCenter(img, rotation);\n<\/pre>\n<p><span style=\"font-family: Helvetica Neue, Arial, Helvetica, sans-serif;\">cheers.<\/span><\/p>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>I have been searching for rotating any display object based on its center and ended up with the stuffs using MatrixTransformer. Though it may helpful to use&#8230; <\/p>\n","protected":false},"author":1,"featured_media":218,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"om_disable_all_campaigns":false,"_mi_skip_tracking":false,"_themeisle_gutenberg_block_has_review":false},"categories":[6,2,3,1],"tags":[11,12,9,10],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/subashselvaraj.com\/index.php\/wp-json\/wp\/v2\/posts\/7"}],"collection":[{"href":"https:\/\/subashselvaraj.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/subashselvaraj.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/subashselvaraj.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/subashselvaraj.com\/index.php\/wp-json\/wp\/v2\/comments?post=7"}],"version-history":[{"count":3,"href":"https:\/\/subashselvaraj.com\/index.php\/wp-json\/wp\/v2\/posts\/7\/revisions"}],"predecessor-version":[{"id":200,"href":"https:\/\/subashselvaraj.com\/index.php\/wp-json\/wp\/v2\/posts\/7\/revisions\/200"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/subashselvaraj.com\/index.php\/wp-json\/wp\/v2\/media\/218"}],"wp:attachment":[{"href":"https:\/\/subashselvaraj.com\/index.php\/wp-json\/wp\/v2\/media?parent=7"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/subashselvaraj.com\/index.php\/wp-json\/wp\/v2\/categories?post=7"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/subashselvaraj.com\/index.php\/wp-json\/wp\/v2\/tags?post=7"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}