{"id":98,"date":"2008-11-19T11:37:39","date_gmt":"2008-11-19T18:37:39","guid":{"rendered":"https:\/\/actionsnippet.com\/?p=217"},"modified":"2008-11-19T11:37:39","modified_gmt":"2008-11-19T18:37:39","slug":"reset-registration-point","status":"publish","type":"post","link":"https:\/\/actionsnippet.com\/?p=98","title":{"rendered":"Reset Registration Point"},"content":{"rendered":"<pre class=\"brush: as3; title: ; notranslate\" title=\"\">\r\n\r\n\/\/ display object target, value - &quot;center&quot; or &quot;upperLeft&quot;\r\nfunction setRegistration(dsp:DisplayObjectContainer, v:String):void {\r\n\tvar i:int;\r\n\tvar child:DisplayObject;\r\n\tvar b:Rectangle=getBounds(dsp);\r\n\tfor (i = 0; i &lt; dsp.numChildren; i++) {\r\n\t\tchild=dsp.getChildAt(i);\r\n\t\tchild.x+=b.x*-1;\r\n\t\tchild.y+=b.y*-1;\r\n\t}\r\n\tif (v==&quot;center&quot;) {\r\n\t\tdsp.x+=dsp.width\/2;\r\n\t\tdsp.y+=dsp.height\/2;\r\n\t\tfor (i = 0; i &lt; dsp.numChildren; i++) {\r\n\t\t\tchild=dsp.getChildAt(i);\r\n\t\t\tchild.x-=dsp.width\/2;\r\n\t\t\tchild.y-=dsp.height\/2;\r\n\t\t}\r\n\t} else if (v == &quot;upperLeft&quot;) {\r\n\t\tif (dsp.parent) {\r\n\t\t\tb=getBounds(dsp.parent);\r\n\t\t\tdsp.x=b.left;\r\n\t\t\tdsp.y=b.top;\r\n\t\t}\r\n\t}\r\n}\r\n\r\n\/\/ example:\r\n\/\/ (make a MovieClip and fill it with, text, shapes etc...)\r\n\r\nsetRegistration(clip, &quot;center&quot;);\r\n\/\/ registration(clip, &quot;upperLeft&quot;);\r\n\r\naddEventListener(Event.ENTER_FRAME, onLoop);\r\nfunction onLoop(evt:Event):void {\r\n\tclip.rotation+=1;\r\n}\r\n<\/pre>\n<p>Teaching beginner flash&#8230; I&#8217;ve noticed people always get confused about the registration point. They think they should be able to move it with the IDE or ActionScript. I always say &#8220;You can&#8217;t change the registration point, you can only change the position of graphical elements in relationship to it.&#8221; Anyway, as a sort of joke one day after class I wrote the above function&#8230; it changes the registration of any DisplayObjectContainer to either &#8220;center&#8221; or &#8220;upperLeft&#8221;.<\/p>\n<p>To test this code out, fill a MovieClip with a bunch of different things (text, graphics, scribbles)&#8230; give it a strange registration point and then run the above code on it. You&#8217;ll be able to tell that the registration has changed by the way the clip rotates. Although I haven&#8217;t been able to break this function, I think it&#8217;s possible that it doesn&#8217;t work under all circumstances.<\/p>\n<p>Using reparenting is a more elegant solution to this issue. Maybe I&#8217;ll post that in the next couple days.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\/\/ display object target, value &#8211; &quot;center&quot; or &quot;upperLeft&quot; function setRegistration(dsp:DisplayObjectContainer, v:String):void { var i:int; var child:DisplayObject; var b:Rectangle=getBounds(dsp); for (i = 0; i &lt; dsp.numChildren; i++) { child=dsp.getChildAt(i); child.x+=b.x*-1; child.y+=b.y*-1; } if (v==&quot;center&quot;) { dsp.x+=dsp.width\/2; dsp.y+=dsp.height\/2; for (i = 0; i &lt; dsp.numChildren; i++) { child=dsp.getChildAt(i); child.x-=dsp.width\/2; child.y-=dsp.height\/2; } } else if (v == [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8,6],"tags":[3,4,62],"class_list":["post-98","post","type-post","status-publish","format-standard","hentry","category-display-list","category-displayobject","tag-actionscript","tag-flash","tag-registration-point"],"_links":{"self":[{"href":"https:\/\/actionsnippet.com\/index.php?rest_route=\/wp\/v2\/posts\/98","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/actionsnippet.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/actionsnippet.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/actionsnippet.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/actionsnippet.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=98"}],"version-history":[{"count":0,"href":"https:\/\/actionsnippet.com\/index.php?rest_route=\/wp\/v2\/posts\/98\/revisions"}],"wp:attachment":[{"href":"https:\/\/actionsnippet.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=98"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/actionsnippet.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=98"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/actionsnippet.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=98"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}