
{"id":376,"date":"2008-01-03T13:40:40","date_gmt":"2008-01-03T12:40:40","guid":{"rendered":"http:\/\/www.matthijskamstra.nl\/blog\/index.php\/2008\/01\/03\/from-as2-to-as3-where-did-it-go-onrelease\/"},"modified":"2008-05-10T23:33:08","modified_gmt":"2008-05-10T22:33:08","slug":"from-as2-to-as3-where-did-it-go-onrelease","status":"publish","type":"post","link":"https:\/\/www.matthijskamstra.nl\/blog\/2008\/01\/03\/from-as2-to-as3-where-did-it-go-onrelease\/","title":{"rendered":"From AS2 to AS3 &#8211; Where did it go &#8211; onRelease"},"content":{"rendered":"<p>Last year I started working with AS3, and after having some startup problems, I&#8217;ve made my first application in it (not online yet).<br \/>\nThe strange thing is, I started a new project and when I had to make a button from a movieclip, I immediately wrote it in AS2&#8230; \ud83d\ude41<\/p>\n<p>That AS2 is embedded deep into my brain and probably more people have this problem.<br \/>\nSo I started this series of post about the stuff that&#8217;s changed in <strong>from AS2 to AS3<\/strong>.<\/p>\n<p>I will probably regurgitate what other people already wrote something about, but it&#8217;s my &#8220;travel&#8221; trough AS3 land.<\/p>\n<h3>onRelease<\/h3>\n<p>One of things I use in every application that I build is onRelease.<\/p>\n<p>This is what the <a href=\"http:\/\/livedocs.adobe.com\/flex\/2\/langref\/migration.html\">ActionScript 2.0 Migration<\/a> has to say about this:<\/p>\n<table width='95%' cellpadding=\"2px\">\n<tr style='background-color:silver'>\n<td><strong>ActionScript 2.0<\/strong><\/td>\n<td><strong>ActionScript 3.0<\/strong><\/td>\n<td><strong>Comments<\/strong><\/td>\n<\/tr>\n<tr style='background-color:#F5F5F5'>\n<td>onRelease() EventHandler<\/td>\n<td>flash.display.InteractiveObject dispatches event: mouseUp <\/td>\n<td>Replaced in the new event model by a mouseUp event. <\/td>\n<\/tr>\n<\/table>\n<p>In AS2 I know 3 ways to use it:<\/p>\n<p><!--more--><\/p>\n<h3>AS2<\/h3>\n<p><em>For this example you need a movieClip named &#8216;<code>reload_mc<\/code>&#8216; and this AS2 code placed in the root<\/em><\/p>\n<p><b>example #1<\/b><\/p>\n<pre><code>\/\/ #1\r\nthis.reload_mc.onRelease = function (){\r\n\ttrace ('onRelease AS2::reload button')\r\n}\r\n<\/code><\/pre>\n<p><b>example #2<\/b><\/p>\n<pre><code>\/\/ #2\r\nthis.reload_mc.onRelease = reloadFunc;\r\n\r\nfunction reloadFunc () {\r\n\ttrace ('onRelease AS2::reload button')\r\n}\r\n<\/code><\/pre>\n<p><b>example #3<\/b><\/p>\n<pre><code>\/\/ #3\r\nvar thisObj = this;\r\nthis.reload_mc.onRelease = function (){\r\n\tthisObj.reloadFunc ();\r\n}\r\nfunction reloadFunc () {\r\n\ttrace ('onRelease AS2::reload button')\r\n}<\/code><\/pre>\n<p>This a little different in AS3, but the good thing is I know of 2 ways to do this, but I only 1 can I explain.<\/p>\n<h3>AS3<\/h3>\n<p><em>For this example you need a movieClip named &#8216;<code>reload_mc<\/code>&#8216; and this AS2 code placed in the root<\/em><br \/>\nExplanation: in AS3 everything is done by Listeners, and so <code>onRelease <\/code>is replaced by <code>MouseEvent.CLICK<\/code>, and to compare the code below and AS2 examples above I would say that example #2 is the AS2 example that resembles AS3 code.<br \/>\n<em>Example #3 is the one I always use but that code is more complex, so that will be another post. <\/em><\/p>\n<p><b>example #1<\/b><\/p>\n<div class=\"showcode\">\n<pre>import flash.events.MouseEvent;\r\n\r\nreload_mc.buttonMode = true; \/\/ show hand icon when mouse is over the movie clip\r\nreload_mc.addEventListener (MouseEvent.CLICK, reloadListener);\r\n\r\nfunction reloadListener ($event:MouseEvent) {\r\n\ttrace ('onRelease AS3::reload button')\r\n}\r\n<\/pre>\n<\/div>\n<p><\/p>\n<div class='highlight'>\n<a href=\"http:\/\/www.brendandawes.com\/\">Brendan Dawes<\/a> created files that helped me a lot: <a href=\"http:\/\/www.brendandawes.com\/news\/as3-for-lazy-bastards-like-me\">as3 for lazy bastards like me<\/a>.<br \/>\nI will probably write about the same subjects as he did in his files&#8230; But people who travel trough AS3 land will probably meet the same problems&#8230;<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Last year I started working with AS3, and after having some startup problems, I&#8217;ve made my first application in it (not online yet). The strange thing is, I started a new project and when I had to make a button from a movieclip, I immediately wrote it in AS2&#8230; \ud83d\ude41 That AS2 is embedded deep [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[22,172,3],"tags":[68,39,97,408,398,114,168],"class_list":["post-376","post","type-post","status-publish","format-standard","hentry","category-as3","category-as3-migration","category-flash","tag-actionscript","tag-as2","tag-as2-to-as3","tag-as3","tag-flash","tag-from-as2-to-as3","tag-migration"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.matthijskamstra.nl\/blog\/wp-json\/wp\/v2\/posts\/376","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.matthijskamstra.nl\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.matthijskamstra.nl\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.matthijskamstra.nl\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.matthijskamstra.nl\/blog\/wp-json\/wp\/v2\/comments?post=376"}],"version-history":[{"count":0,"href":"https:\/\/www.matthijskamstra.nl\/blog\/wp-json\/wp\/v2\/posts\/376\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.matthijskamstra.nl\/blog\/wp-json\/wp\/v2\/media?parent=376"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.matthijskamstra.nl\/blog\/wp-json\/wp\/v2\/categories?post=376"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.matthijskamstra.nl\/blog\/wp-json\/wp\/v2\/tags?post=376"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}