Language Actionscript 3
(Configurable)
Date: | 08/06/08 |
Author: | Jason Tye |
URL: | n/a |
Comments: | 6 |
Info: | http://www.adobe.com/devnet/actionscript/ |
Score: | (2.59 in 17 votes) |
package { import flash.display.MovieClip; public class Beer extends MovieClip { /* Set default song parameters: 'beer' in 'bottles' on a 'wall' */ private var bottleCount:int = 5; private var liquid:String = 'beer'; private var container:String = 'bottle'; private var surface:String = 'wall'; /* song is comprised of 4 verses, which we loop through for each bottle */ private var verse:int = 0; private var itVsOne:String = 'one'; private var plural:String = 's'; private var outNumber:String = bottleCount.toString(); /* song line for output */ private var songLine:String; public function Beer() { /* Loop through 4 times the numeber of bottles, 4 verses for each bottle */ var loopCount:int = bottleCount*4; for (var i:int=0; i<loopCount; i++) { sing(); } } /* set plural states*/ private function checkPlural(count:int):void { if (count == 1) { plural = ''; outNumber = 'one' itVsOne = 'it'; } else { outNumber = count.toString(); } } private function sing():String { switch (verse) { case 0 : songLine = outNumber+' '+container+plural+' of '+liquid+' on the '+surface; verse++; break; case 1 : songLine = outNumber+' '+container+plural+' of '+liquid; verse++; break; case 2 : songLine = 'take '+itVsOne+' down, pass it around'; verse++; break; case 3 : bottleCount--; checkPlural(bottleCount); verse = 0; if (bottleCount == 0) { songLine = 'no more '+container+'s of '+liquid+' on the '+surface; } else { songLine = outNumber+' '+container+plural+' of '+liquid+' on the '+surface; } break; default : } return songLine; } } }
Download Source | Write Comment
Download Source | Write Comment
Add Comment
Please provide a value for the fields Name,
Comment and Security Code.
This is a gravatar-friendly website.
E-mail addresses will never be shown.
Enter your e-mail address to use your gravatar.
Please don't post large portions of code here! Use the form to submit new examples or updates instead!
Comments
Gaggo said on 11/20/08 16:16:38
hmm, just 4?
Goura said on 02/20/09 22:00:22
The beer sings? LOL
Kyle said on 09/19/09 09:37:09
I tried this but it just says package can not be nested any advice?
barrym said on 08/27/10 07:19:26
I understand the four-part phrase (verse) logic, but two problems are apparent: :-(
1) The song starts at 5 bottles rather than 99 (an easy fix)
2) The "Go to the store ... " verse is missing (a slightly less easy fix)
On the bright side, I like the flexibility of the program to sing about different
containers, liquids and surfaces.
guest said on 09/26/10 19:32:14
awfull code! that could be much more easier!
barrym said on 09/27/10 06:36:55
@guest: Please feel free to submit an alternate "more easier" (sic!) version. I
don't know enough about Actionscript 3 to do one myself, but I and many others can
offer our honest opinions (from varying levels of experience) about your code's
appearance and quality. It's a level playing field, and your version could easily
work its way to the top, but only if you submit it!