{"id":85,"date":"2008-11-06T00:00:32","date_gmt":"2008-11-06T07:00:32","guid":{"rendered":"https:\/\/actionsnippet.com\/?p=79"},"modified":"2008-11-06T00:00:32","modified_gmt":"2008-11-06T07:00:32","slug":"toggle-visible","status":"publish","type":"post","link":"https:\/\/actionsnippet.com\/?p=85","title":{"rendered":"Toggle .visible"},"content":{"rendered":"<pre class=\"brush: as3; title: ; notranslate\" title=\"\">\r\n\/\/ toggle a DisplayObject&#039;s visible property\r\nvar shape = new Shape();\r\n\r\nshape.visible = !shape.visible;\r\ntrace(shape.visible); \/\/ outputs false\r\n\r\nshape.visible = !shape.visible;\r\ntrace(shape.visible); \/\/ outputs true\r\n\r\nshape.visible = !shape.visible;\r\ntrace(shape.visible); \/\/ outputs false\r\n\r\nshape.visible = !shape.visible;\r\ntrace(shape.visible);  \/\/ outputs true\r\n<\/pre>\n<p>This is pretty obvious to anyone with a full understanding of the ! operator. It&#8217;s useful for things<br \/>\nlike checkboxes and other types of toggle buttons. The first time I ever encountered this technique<br \/>\nwas in processing source&#8230; in one of the demos on <a href=\"http:\/\/www.toxi.co.uk \">toxi.co.uk<\/a><\/p>\n<p>Here&#8217;s another quick example you can run in your timeline:<\/p>\n<pre class=\"brush: as3; title: ; notranslate\" title=\"\">\r\nvar circle:Shape =  new Shape();\r\ncircle.graphics.beginFill(0xFF0000);\r\ncircle.graphics.drawCircle(0, 0,10);\r\ncircle.x = 80;\r\ncircle.y = 105;\r\naddChild(circle)\r\n\r\nvar btn:TextField = new TextField();\r\nbtn.text = &quot;click this text to toggle red circle&#039;s visibility&quot;;\r\nbtn.x = btn.y = 100;\r\nbtn.selectable = false;\r\nbtn.border = true;\r\nbtn.autoSize = TextFieldAutoSize.LEFT;\r\naddChild(btn);\r\n\r\nbtn.addEventListener(MouseEvent.CLICK, onClick);\r\nfunction onClick(evt:MouseEvent):void{\r\n\tcircle.visible = !circle.visible;\r\n}\r\n<\/pre>\n<p>Because &#8220;not false&#8221; is true.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\/\/ toggle a DisplayObject&#039;s visible property var shape = new Shape(); shape.visible = !shape.visible; trace(shape.visible); \/\/ outputs false shape.visible = !shape.visible; trace(shape.visible); \/\/ outputs true shape.visible = !shape.visible; trace(shape.visible); \/\/ outputs false shape.visible = !shape.visible; trace(shape.visible); \/\/ outputs true This is pretty obvious to anyone with a full understanding of the ! operator. It&#8217;s useful [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[36],"tags":[],"class_list":["post-85","post","type-post","status-publish","format-standard","hentry","category-operators"],"_links":{"self":[{"href":"https:\/\/actionsnippet.com\/index.php?rest_route=\/wp\/v2\/posts\/85","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=85"}],"version-history":[{"count":0,"href":"https:\/\/actionsnippet.com\/index.php?rest_route=\/wp\/v2\/posts\/85\/revisions"}],"wp:attachment":[{"href":"https:\/\/actionsnippet.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=85"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/actionsnippet.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=85"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/actionsnippet.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=85"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}