So there have been a number of questions on my kinda recent post about making a button in Flash CS3 or Flash CS4 using ActionScript 3.0. I will do the next couple posts on how to do the things in the questions (and actually check em out in Flash, and make an FLA to download). Update: More links about buttons and button code at the end of this post.
So if you haven’t already read or don’t know how to make a single button, head on over to the post linked above. Here, I’ll continue on to multiple buttons.
Say you have a couple buttons on a page, and you want one to go to one URL, and the second one to go to a different URL – you need to change your function names in your code so you don’t have multiples with the same name. So, you would need to do something like this:
thumbsdown_btn.addEventListener(MouseEvent.MOUSE_DOWN, thumbDownHandler); function thumbDownHandler(event:MouseEvent):void { navigateToURL(new URLRequest("http://msdn2.microsoft.com/en-us/silverlight/default.aspx")); } thumbsup_btn.addEventListener(MouseEvent.MOUSE_DOWN, thumbUpHandler); function thumbUpHandler(event:MouseEvent):void { navigateToURL(new URLRequest("http://www.adobe.com/devnet/flash/")); }
Note the thumbDownHandler and thumbupHandler in the code.
The source file: Mutliple buttons to URLs
So some people are instead targeting multiple frames. In that case, the code would look like this:
stop(); first_btn.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler1); function mouseDownHandler1(event:MouseEvent):void { gotoAndStop(5); } second_btn.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler2); function mouseDownHandler2(event:MouseEvent):void { gotoAndStop(10); }
The source file: Mutliple buttons to frames
MORE INFORMATION ON BUTTONS:
- For basic information on creating a button in ActionScript 3.0, see this post: http://flashthusiast.com/2008/02/25/making-a-button-work-in-flash-cs3-with-actionscript-30-its-not-too-bad/
- For info on targeting scenes or frames within a single scene, see this post here: http://flashthusiast.com/2008/07/31/creating-buttons-that-link-to-different-scenes-using-actionscript-30/
- For info on targeting different windows with your button code (such as the same window instead of a new window), see this post: http://flashthusiast.com/2009/07/24/controlling-the-window-a-button-click-opens-using-actionscript-30-in-flash/
- For information on creating MovieClip buttons in Flash, see this: http://flashthusiast.com/2008/10/19/movie-clip-buttons-in-a-fight-its-as2-vs-as3-again/
- For information on controlling the browser window target that opens when a button is clicked, see: http://flashthusiast.com/2008/10/19/movie-clip-buttons-in-a-fight-its-as2-vs-as3-again/
- For info on creating buttons that go to the next frame or previous frame on the timeline, see: http://flashthusiast.com/2010/05/05/buttons-in-flash-using-actionscript-3-0-going-to-next-frame-and-previous-frame/