{"id":102,"date":"2007-07-12T11:30:58","date_gmt":"2007-07-12T16:30:58","guid":{"rendered":"http:\/\/www.pixelwit.com\/blog\/2007\/07\/12\/classes-and-operators\/"},"modified":"2009-08-14T05:35:43","modified_gmt":"2009-08-14T10:35:43","slug":"classes-and-operators","status":"publish","type":"post","link":"https:\/\/www.pixelwit.com\/blog\/2007\/07\/12\/classes-and-operators\/","title":{"rendered":"Classes and Operators"},"content":{"rendered":"<p>I&#8217;m certainly no expert when it comes to writing Flash classes, but here&#8217;s my question.  Can you use operators on class members?  I did a quick search on the web and only found information for C++ where it&#8217;s called &#8220;overloading operators&#8221; but I didn&#8217;t find anything about it in ActionScript.  In case you&#8217;re curious why I&#8217;d like to use operators on a class, here&#8217;s what I was thinking&#8230;<!--more--><\/p>\n<p>Let&#8217;s say I create 2 instances of the Point class:<\/p>\n<div class=\"codecolorer-container actionscript default\" style=\"overflow:auto;white-space:nowrap;width:100%;\"><div class=\"actionscript codecolorer\"><span class=\"co1\">\/\/<\/span><br \/>\n<span class=\"kw2\">var<\/span> a = <span class=\"kw2\">new<\/span> Point<span class=\"br0\">&#40;<\/span><span class=\"nu0\">1<\/span>, <span class=\"nu0\">2<\/span><span class=\"br0\">&#41;<\/span>;<br \/>\n<span class=\"kw2\">var<\/span> b = <span class=\"kw2\">new<\/span> Point<span class=\"br0\">&#40;<\/span><span class=\"nu0\">3<\/span>, <span class=\"nu0\">4<\/span><span class=\"br0\">&#41;<\/span>;<br \/>\n<span class=\"co1\">\/\/<\/span><br \/>\n<span class=\"co1\">\/\/ I'd like to multiply point A by point B.<\/span><br \/>\n<span class=\"kw2\">var<\/span> c = a <span class=\"sy0\">*<\/span> b;<br \/>\n<span class=\"co1\">\/\/ Essentially saying:<\/span><br \/>\n<span class=\"co1\">\/\/ c = new Point (3, 8);<\/span><br \/>\n<span class=\"co1\">\/\/<\/span><br \/>\n<span class=\"co1\">\/\/ I'd also like to multiply point A by a number.<\/span><br \/>\n<span class=\"kw2\">var<\/span> d = a <span class=\"sy0\">*<\/span> <span class=\"nu0\">6<\/span>;<br \/>\n<span class=\"co1\">\/\/ Essentially saying:<\/span><br \/>\n<span class=\"co1\">\/\/ d = new Point(6, 12);<\/span><br \/>\n<span class=\"co1\">\/\/<\/span><\/div><\/div>\n<p>Of course I&#8217;d also like to be able add, subtract and divide points.  And while I&#8217;m at it, being able to use assignment operators such as +=, -=, \/= and *= would be nice too.<\/p>\n<p>Is this something that is supported in ActionScript 3?  If not, do you think it will be?  Do you think it should be?<\/p>\n<p>Leave a comment!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>A brief discussion about adding support for operator overloading in Flash ActionScript so classes such as Points can be added and multiplied.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"ngg_post_thumbnail":0,"footnotes":""},"categories":[8],"tags":[23],"class_list":["post-102","post","type-post","status-publish","format-standard","hentry","category-flash","tag-actionscript"],"_links":{"self":[{"href":"https:\/\/www.pixelwit.com\/blog\/wp-json\/wp\/v2\/posts\/102","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.pixelwit.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.pixelwit.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.pixelwit.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.pixelwit.com\/blog\/wp-json\/wp\/v2\/comments?post=102"}],"version-history":[{"count":0,"href":"https:\/\/www.pixelwit.com\/blog\/wp-json\/wp\/v2\/posts\/102\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.pixelwit.com\/blog\/wp-json\/wp\/v2\/media?parent=102"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.pixelwit.com\/blog\/wp-json\/wp\/v2\/categories?post=102"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.pixelwit.com\/blog\/wp-json\/wp\/v2\/tags?post=102"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}