
{"id":382,"date":"2008-07-30T10:33:31","date_gmt":"2008-07-30T09:33:31","guid":{"rendered":"http:\/\/www.matthijskamstra.nl\/blog\/?p=382"},"modified":"2008-09-02T10:36:39","modified_gmt":"2008-09-02T09:36:39","slug":"from-as2-to-as3-where-did-it-go-attachmovie","status":"publish","type":"post","link":"https:\/\/www.matthijskamstra.nl\/blog\/2008\/07\/30\/from-as2-to-as3-where-did-it-go-attachmovie\/","title":{"rendered":"From AS2 to AS3 &#8211; Where did it go &#8211; attachMovie"},"content":{"rendered":"<p>Where did <code>attachMovie<\/code> go in AS3?<\/p>\n<p>Once I started using <code>attachMovie<\/code> instead <code>duplicateMovieClip<\/code> my AS2 life became a lot easier.<\/p>\n<p>What has the <a href=\"http:\/\/livedocs.adobe.com\/flex\/2\/langref\/migration.html\">ActionScript 2.0 Migration<\/a> to say about this subject:<\/p>\n<table width='95%' border=\"1\" cellpadding=\"0\" cellspacing=\"0\">\n<tr style='background-color:silver'>\n<td><strong>ActionScript&nbsp;2.0&nbsp;<\/strong><\/td>\n<td><strong>ActionScript&nbsp;3.0&nbsp;<\/strong><\/td>\n<td><strong>Comments<\/strong><\/td>\n<\/tr>\n<tr style='background-color:#F5F5F5'>\n<td>attachMovie() Method<\/td>\n<td>Removed<\/td>\n<td> In ActionScript 3.0, use addChild() to add child display objects.<\/td>\n<\/tr>\n<\/table>\n<p>Removed&#8230; wtf? and you can read the documentation till you are old and gray, but you won&#8217;t find a answer there.<\/p>\n<p>In AS2 I know 3 ways to attach a movie to the stage:<\/p>\n<p><!--more--><\/p>\n<h3>AS2<\/h3>\n<p><em>For this example you need a movieClip in the library (<em>right-click<\/em> >> Linkage&#8230; >> activate &#8216;Export for ActionScript&#8217;) with the Indentifier &#8216;<code>ImageMovie<\/code>&#8216; and this AS2 code placed in the root<\/em><\/p>\n<div class='highlight'>I used the name &#8216;<code>ImageMovie<\/code>&#8216; because it also use in an example from <a href=\"http:\/\/www.brendandawes.com\/\">Brendan Dawes<\/a> that I use in AS3 examples. And to keep the movieClip the same through all code I kept the name.<\/div>\n<p><b>example #1<\/b><br \/>\n[as]\/\/ #1<br \/>\nthis.attachMovie(&#8216;ImageMovie&#8217;, &#8216;ImageMovie2&#8217; , 10);<br \/>\n[\/as]<\/p>\n<p><b>example #2<\/b><br \/>\n[as]\/\/ #2<br \/>\nvar myImageMovie:MovieClip = this.attachMovie(&#8216;ImageMovie&#8217;, &#8216;ImageMovie2&#8217; , 10);<br \/>\nmyImageMovie._x = 20;<br \/>\nmyImageMovie._y = 20;<br \/>\n[\/as]<\/p>\n<p><b>example #3<\/b> (my personal favorite)<br \/>\n[as]\/\/ #3<br \/>\nthis.attachMovie(&#8216;ImageMovie&#8217;, &#8216;ImageMovie2&#8217; , 10 , {_x:20,_y:20});<br \/>\n[\/as]<\/p>\n<p>Oke, now in AS3:<\/p>\n<h3>AS3<\/h3>\n<p><em>For this example you need a movieClip in the library (<em>right-click<\/em> >> Linkage&#8230; >> activate &#8216;Export for ActionScript&#8217;) with the Indentifier &#8216;<code>ImageMovie<\/code>&#8216; and this AS3 code placed in the root<\/em><\/p>\n<p><b>example #1<\/b><br \/>\n[as]\/\/ #1<br \/>\nthis.addChild(new ImageMovie());<br \/>\n[\/as]<\/p>\n<p><b>example #2<\/b><br \/>\n[as]\/\/ #2<br \/>\nvar myImageMovie = this.addChild(new ImageMovie());<br \/>\nmyImageMovie.x = 20;<br \/>\nmyImageMovie.y = 20;<br \/>\n[\/as]<\/p>\n<div class=\"update\"><strong>Update #1:<\/strong> I&#8217;m using this a lot these days, so I will let you see how I use it now<\/div>\n<p><b>example #2a<\/b><br \/>\n[as]\/\/ #2a<br \/>\nvar myImageMovie:ImageMovie = new ImageMovie();<br \/>\nmyImageMovie.x = 20;<br \/>\nmyImageMovie.y = 20;<br \/>\nthis.addChild (myImageMovie);<br \/>\n[\/as]<\/p>\n<p><b>example #3<\/b><br \/>\nThis code is a copy of the code from <a href=\"http:\/\/www.brendandawes.com\">brendandawes.com<\/a> and you should visit  <a href=\"http:\/\/www.brendandawes.com\/code\/as3-for-lazy-bastards-like-me\">as3 for lazy bastards (like me)<\/a><\/p>\n<p>you need a AS file with the name &#8220;ImageMovie.as&#8221; with this code in there<br \/>\n[as]<br \/>\n\/\/ #3<br \/>\npackage {<\/p>\n<p>\timport flash.display.MovieClip;<\/p>\n<p>\tpublic class ImageMovie extends MovieClip {<\/p>\n<p>\t\tfunction ImageMovie(xPos:Number = 0,yPos:Number = 0) {<br \/>\n\t\t\tthis.x = xPos;<br \/>\n\t\t\tthis.y = yPos;<br \/>\n\t\t}<br \/>\n\t}<br \/>\n}<br \/>\n[\/as]<br \/>\nand you need this code in the timeline, because the movieClip in the Library is linked to this AS file you can talk to it directly:<br \/>\n[as]<br \/>\n\/*<br \/>\nHow to &#8220;attachMovie&#8221; in as3<br \/>\n*\/<br \/>\nvar imageMC:ImageMovie = new ImageMovie(50,50);<br \/>\nthis.addChild(imageMC);<br \/>\n[\/as]<br \/>\nand the it will work the same as option 3 in AS2<\/p>\n<p>Here you can find another explanation about this subject: by <a href=\"http:\/\/www.airtightinteractive.com\/news\/?p=78\">Airtight Interactive<\/a><\/p>\n<p>I hope this will clear up some issues you have, happy coding \ud83d\ude09 <\/p>\n","protected":false},"excerpt":{"rendered":"<p>Where did attachMovie go in AS3? Once I started using attachMovie instead duplicateMovieClip my AS2 life became a lot easier. What has the ActionScript 2.0 Migration to say about this subject: ActionScript&nbsp;2.0&nbsp; ActionScript&nbsp;3.0&nbsp; Comments attachMovie() Method Removed In ActionScript 3.0, use addChild() to add child display objects. Removed&#8230; wtf? and you can read the documentation [&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,114,168],"class_list":["post-382","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-from-as2-to-as3","tag-migration"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.matthijskamstra.nl\/blog\/wp-json\/wp\/v2\/posts\/382","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=382"}],"version-history":[{"count":3,"href":"https:\/\/www.matthijskamstra.nl\/blog\/wp-json\/wp\/v2\/posts\/382\/revisions"}],"predecessor-version":[{"id":474,"href":"https:\/\/www.matthijskamstra.nl\/blog\/wp-json\/wp\/v2\/posts\/382\/revisions\/474"}],"wp:attachment":[{"href":"https:\/\/www.matthijskamstra.nl\/blog\/wp-json\/wp\/v2\/media?parent=382"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.matthijskamstra.nl\/blog\/wp-json\/wp\/v2\/categories?post=382"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.matthijskamstra.nl\/blog\/wp-json\/wp\/v2\/tags?post=382"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}