ch00se_JukeBox (Opensource)

19 posts

Flag Post

ch00se_JukeBox is an opensource game add on for anyone to try out/modify/ ignore. The main files can be found here:

Feel free to download these files and do what you will with them. The main purpose of ch00se_JukeBox is to provide a music player for your game. Just plug your game code into the code and now your game has selectable music. Also, I’ve included the NetSearch Trivia code in case anyone wanted to see it.

A note that may or may not be of importance is that I coded this using Flash MX (that’s version 7) in order to reach a broader audience, but it also presented some limitations. Again, feel free to modify it to better suite your needs.

Let me know of any issues you run into.


EDIT: Version 1.3 is now available by clicking the link above!

Flag Post

I was just wondering if anyone has tinkered with the code at all. I think it would be great to see someone else’s modifications, large or small. If anyone has suggestions or comments on how to make the code more user friendly let me know. I tried to make the basics (change colors, change songs, etc…) as easy as changing one line of code.

Flag Post

Just added a new version of ch00se_JukeBox: Version 1.1

Version notes can be found in the code

Class files are unchanged

Flag Post

Just added a new version of ch00se_JukeBox: Version 1.2

Version notes can be found in the code

Class files are unchanged

Flag Post

hey, im new to AS, infact i just got Flash CS3 and I cant wait to learn to code flash games. I learn pretty well from looking at examples so i think this open source of yours will be a great help. While I am busy I will try and find some time to rip everything apart and figure out whats going on :P . I’ll let you know when i have made an update. Thanks for the code

Flag Post

No problem, glad to see someone is going to pick it apart :) Feel free to ask me any questions.

Flag Post

Hi ch00se,

I just took a quick peek at your initializeDisplay class and I noticed a few things which could be improved as far as OOP coding goes…

I see that you are defining a lot of “getter” functions which return the values of the properties; however, the properties themselves have not been defined as “private,” so it’s pretty redundant since no calculations are performed on the returned value and the properties themselves can just be accessed directly using dot notation.

The correct way to do it would be to define the properties as being private, as such:

private var bgColor:String;

Once they are defined as private, any attempt to reference the property directly will result in a compiler error.

Another problem I noticed here: this bgColor property should be a Number, not a String. Hex values in Flash such as 0xffffff (white) or 0×0000ff (blue) etc. are best represented as numbers, it will be less of a hassle for you that way.

Additionally, if you are defining getter and setter functions, there is a specific syntax for doing that as well:

public function get property (): returnType { 
 // your statements here 

Then, you will be able to use dot notation to access the “property” in your code, but instead of directly accessing the property, it will be calling the getter function instead. Usually this is good if you are going to be performing some type of calculation on the returned value, but it is also considered a best practice so it’s good to do anyway.

Okay, hope that helps :)

Flag Post

I know i C# language you can do:

public int Property{
get{ return propertyvar; }
set { propertyvar = value; }

i forgot the proper syntax of it, its been a while, either way if you call Property it would return the value of propertyvar, but if you call propertyvar( 2 ) it will set. Does AS support this and would it be a better way to define the getter and setters in this case ( i know int would be changed to Number)

Flag Post

In AS, you have the get and set keywords, which will allow you to define your getter and setter functions, respectively, in the manner which I described above.

Obviously, the getter will have a return type defined, and the setter will have an argument passed in.

public function set property(varName) { 
 // your statements here 

C# and AS are different languages, even though the syntax and control structures are similar, so it would be best to look into some ActionScript books as I’m sure there’s a lot of major differences between the two languages.

Flag Post

ya i was just curious if they had a combined function, but thanks for clarification

Flag Post

Indie and SwiftStriker, thanks for the input. Thanks for pointing out the private var thing, I just missed it. As for the getters and setters, I’m a long time Java developer so it’ll be hard to get me out of my old ways, but I’ll try the get and set syntax. I’m a huge encapsulation fan, so almost all vars are going to be private anyway… the dot notation always surprises me in AS. For example.. it’s amazing to me that you can make movieclips within movieclips (as many levels deep as you want), and then access them using dot notation. As for C# I’ve actually done some projects in that language as well and I have some freeware apps if you guys are interested… they are .exes though so it would be a “trust the developer” type thing.

I have to admit that you will probably find many things wrong with the JukeBox code, and I definitely know there are better ways to go about it. But its main purpose was to help others get started and maybe even to create their first game, so I left a lot open. However, I’m up to change the code to be more helpful to everyone else since I don’t want to get people starting on the wrong foot! Thanks for both of your inputs.

I should probably also take this opportunity to say that anyone should feel free to make changes to the code and send the code to me to put online, or do it yourself if you have hosting and post in this thread.

Flag Post

No problem.

One more thing to note is that the variable (property) hasInitialized could be a Boolean datatype instead of a String.

So, instead of setting a string value:

this.hasInitialized = “yes”;

You can set a boolean value:
this.hasInitialized = true;

I decided that instead of hosting the file, I would post it here so others can see what we’re talking about… In order to use this updated class in the JukeBox, you’ll need to update all those function calls to match the names of the getter and setter functions.

Here’s the updated initializeDisplay class:

class initializeDisplay
private var songList:Array = new Array();
private var hasInitialized:Boolean;
private var nBgColor:Number;
private var nButtonBGColor:Number;
private var buttonBuffer:Number;
private var currentSongButton:String;
private var nButtonBGColor_over:Number;
private var nButtonTextColor:Number;
private var buttonTextSize:Number;
private var nMenuButtonBGColor:Number;
private var nMenuButtonBGColor_over:Number;
private var nMenuButtonTextColor:Number;
private var menuButtonTextSize:Number;

function initializeDisplay(songsForList:Array)
//this will be the color of the movie’s background.
//change this to change the background color.
this.nBgColor = 0×660000;

//this will be the color of all the buttons’ background.
//change this to change their background colors.
this.nButtonBGColor = 0×330000;

//this will be the color of all the buttons’ background
//when the button is hovered over with the mouse.
//change this to change the color
this.nButtonBGColor_over = 0xFF0000;

//this will be the color of all the buttons’ text color
//change this to change their text colors.
this.nButtonTextColor = 0xFFFAFA;

//this will be the sizer of all the buttons’ text
//change this to change the size of their text.
this.buttonTextSize = 20;

//the buffer will increase the space between buttons
this.buttonBuffer = 10;

//this just signals that a new object has been created
this.hasInitialized = true;

//copying the passed array into the class’ array
this.songList = songsForList;

//changing this hex value will change the background color of the menu buttons
this.nMenuButtonBGColor = 0×330000;

//changing this hex value will change the hover background color of the menu buttons
this.nMenuButtonBGColor_over = 0xFF0000;

//changing this hex value will change the text color of the menu buttons
this.nMenuButtonTextColor = 0xFFFAFA;

//changing this value will change the text size of the menu buttons
this.menuButtonTextSize = 20;


//function to get the background color to be used for the buttons
public function get buttonBGColor():Number
return nButtonBGColor;

//function to get the background color to be used for the stage’s background
public function get BGColor():Number
return nBgColor;

//function for checking to see if the initializeMusic Object has been created
//this is set as a string since it will automatically return “undefined” if it
//has not yet been created.
public function get getInitializedStatus():Boolean
return hasInitialized;

//return the button buffer number
public function get getButtonBuffer():Number
return this.buttonBuffer;

//function for setting current song button
function setCurrentSongButton(theCurrentSongButton:String):Void
this.currentSongButton = theCurrentSongButton;

//function for getting current song button
function getCurrentSongButton():String
return this.currentSongButton;

//function for getting the button’s background color when hovered over
public function get buttonBGColor_over():Number
return nButtonBGColor_over;

//function for getting the button’s text color
public function get buttonTextColor():Number
return nButtonTextColor;

//function for getting the button’s text size
function getButtonTextSize():Number
return this.buttonTextSize;

//function for getting the menu button’s background color
public function get menuButtonBGColor():Number
return nMenuButtonBGColor;

//function for getting the menu button’s background color when hovered over
public function get menuButtonBGColor_over():Number
return nMenuButtonBGColor_over;

//function for getting the menu button’s text size
function getMenuButtonTextSize():Number
return this.menuButtonTextSize;

//function for getting the menu button’s text color
public function get menuButtonTextColor():Number
return nMenuButtonTextColor;


DISCLAIMER: I only updated the properties and getter functions for those variables that were mistyped… the rest is the same, so it should be updated also.

Flag Post

Ahhhhh. Indie, thanks for the tips, however I see an issue here. I am coding in AS 2.0, and I see you are adding some 3.0 code. I didn’t catch this at first, but when I tried to implement your code everything went haywire. If you read the above post I state that I am using AS 2.0 in order to reach a broader audience. However, I like the fact that you’re showing the AS 3.0 code, so if others are using the newer AS they will be able to take advantage of the features available. If I find some time I may even compile a separate 3.0 JukeBox (or you could if you wanted to take the time). So now I have an excuse of why I wasn’t using the get and set syntax! ;)

And I should note that I used a string for initialization on purpose. I needed to change the value at some point in the early stages. But I removed that code, so boolean is fine. It should also be noted that the code in the .fla needs to be changed to match these changes if implemented.

Thanks for the addition!

Flag Post

This is AS 2.0 code… what version of Flash are you running?

I like the fact that you’re showing the AS 3.0 code […]

The class file I posted above is ActionScript 2.0, and I edited everything except the original parts which were working fine.

I use Flash 8 (Macromedia) and it works just fine…

It should also be noted that the code in the .fla needs to be changed to match these changes if implemented.

I did mention this in the “DISCLAIMER” above. I’m just demonstrating how to write As 2.0 code. Some of the code that I posted above is your original code… but it should still compile with no errors.

Flag Post

Indie, I stand corrected. In the ActionScript 3.0 Language and Components Reference it lists “get” and “set” as AS 3.0 so I assumed it meant that it was a new addition. However, it then has a note saying you must use AS 2.0 for this to work… strange documentation. Anyway, I found my problem. The parentheses () need to be taken out since it is using get and set. I’m not sure I like this, but we might as well go with it.

Flag Post

lol now u guys are confusing me, but im using AS 3.0 so im gunna tweak indie’s code ( just for the proper syntax of my version)

Flag Post

The parentheses () need to be taken out since it is using get and set. I’m not sure I like this, but we might as well go with it.

If you mean out of the line trying to access it, yes. Thats the point of getter and setter methods, it adds a property to the object and you then access the data like you would a property, not as a function.

Flag Post

Right, thanks for clarifying arcane. And sorry for the confusion SwiftStriker. Let us know if you need any help. When I get time I will edit my original post to contain all of the info from the responses.

Flag Post

Just added a new version of ch00se_JukeBox: Version 1.3

Version notes can be found in the code

Class files are unchanged