{"id":262,"date":"2009-04-22T10:40:32","date_gmt":"2009-04-22T17:40:32","guid":{"rendered":"https:\/\/actionsnippet.com\/?p=1206"},"modified":"2009-04-22T10:40:32","modified_gmt":"2009-04-22T17:40:32","slug":"infinity-scroller-repeating-navigation","status":"publish","type":"post","link":"https:\/\/actionsnippet.com\/?p=262","title":{"rendered":"Infinity Scroller (repeating navigation)"},"content":{"rendered":"<pre lang=\"actionscript3\" line=\"1\">\r\nvar buttonsWidth:Number = 0;\r\nvar buttonsA:Sprite = new Sprite();\r\nvar buttonsB:Sprite = new Sprite();\r\nvar nav:Sprite = new Sprite();\r\n\r\nvar buttonData:Array = [\"one\", \"two\", \"three\", \"four\", \"five\", \"six\", \r\n                                    \"seven\", \"eight\", \"nine\", \"ten\"];\r\n\r\nbuildNav();\r\n\r\nfunction buildNav():void{\r\n\tnav.addChild(buttonsA);\r\n        nav.addChild(buttonsB);\r\n        addChild(nav);\r\n\tbuildButtons(buttonsA);\r\n\tbuttonsWidth = buttonsA.width;\r\n\tbuildButtons(buttonsB);\r\n\tbuttonsB.x = buttonsWidth;\r\n}\r\n\r\nfunction buildButtons(container:Sprite):void{\r\n\tfor (var i:int = 0; i<buttonData.length; i++){\r\n\t\tvar b:MovieClip = new MovieClip();\r\n\t        with(b.graphics){\r\n\t\t\tlineStyle(0,0x000000);\r\n\t\t\tbeginFill(0xCCCCCC);\r\n\t\t\tdrawRect(0,0,100,30);\r\n\t\t}\r\n\t\tb.x = i * b.width;\r\n\t\tvar txt:TextField = new TextField();\r\n\t\ttxt.scaleX = txt.scaleY = 1.5\r\n\t\ttxt.selectable = false;\r\n\t\ttxt.multiline = false;\r\n\t\ttxt.autoSize = TextFieldAutoSize.LEFT;\r\n\t\ttxt.mouseEnabled = false;\r\n\t\ttxt.x = 3;\r\n\t\ttxt.text = buttonData[i];\r\n\t\tb.buttonMode = true;\r\n\t\tb.addChild(txt)\r\n\t        container.addChild(b);\r\n\t}\r\n}\r\n\r\nvar velX:Number = 0;\r\nvar navSpeed:Number = 8;\r\nvar leftSide:Number = stage.stageWidth \/ 3;\r\nvar rightSide:Number = leftSide * 2;\r\naddEventListener(Event.ENTER_FRAME, onRunNav);\r\nfunction onRunNav(evt:Event):void {\r\n\tif (mouseY < 100){\r\n\t\tif (mouseX  < leftSide){\r\n\t\t\tvelX = navSpeed;\r\n\t\t}\r\n\t\tif (mouseX > rightSide){\r\n\t\t\tvelX = -navSpeed;\r\n\t\t}\r\n\t\tif (nav.x < -buttonsWidth){\r\n\t\t\tnav.x = -navSpeed;\r\n\t\t}\r\n\t\tif (nav.x > -navSpeed){\r\n\t\t\tnav.x = -buttonsWidth \r\n\t\t}\r\n\t}\r\n\tvelX *=.9;\r\n\tnav.x += velX;\r\n}\r\n<\/pre>\n<p>This snippet creates a navigation that will scroll to the left or right forever &#8211; the buttons will simply repeat. I&#8217;m not a big fan of this kind of navigation &#8211; especially if you have lots of buttons, but it seems to be a common request. This technique can be modified for use in a side-scroller style game.<\/p>\n<p><i>Just added a new syntax highlighter, please posts comments if you have any issues viewing this snippet.<\/i><\/p>\n","protected":false},"excerpt":{"rendered":"<p>var buttonsWidth:Number = 0; var buttonsA:Sprite = new Sprite(); var buttonsB:Sprite = new Sprite(); var nav:Sprite = new Sprite(); var buttonData:Array = [&#8220;one&#8221;, &#8220;two&#8221;, &#8220;three&#8221;, &#8220;four&#8221;, &#8220;five&#8221;, &#8220;six&#8221;, &#8220;seven&#8221;, &#8220;eight&#8221;, &#8220;nine&#8221;, &#8220;ten&#8221;]; buildNav(); function buildNav():void{ nav.addChild(buttonsA); nav.addChild(buttonsB); addChild(nav); buildButtons(buttonsA); buttonsWidth = buttonsA.width; buildButtons(buttonsB); buttonsB.x = buttonsWidth; } function buildButtons(container:Sprite):void{ for (var i:int = 0; i [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[13,98],"tags":[3,4],"class_list":["post-262","post","type-post","status-publish","format-standard","hentry","category-motion","category-ui","tag-actionscript","tag-flash"],"_links":{"self":[{"href":"https:\/\/actionsnippet.com\/index.php?rest_route=\/wp\/v2\/posts\/262","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=262"}],"version-history":[{"count":0,"href":"https:\/\/actionsnippet.com\/index.php?rest_route=\/wp\/v2\/posts\/262\/revisions"}],"wp:attachment":[{"href":"https:\/\/actionsnippet.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=262"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/actionsnippet.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=262"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/actionsnippet.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=262"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}