I am about to start a new website and i am wondering about how to write a prototype function for it. I am using flash MX.
i have never written prototypes before, but have used a couple (especially the preloader prototype in best of Kirupa - brilliant)!
What i want to do sounds pretty simple but i always have problems with it.
basically there are 50 odd text buttons throughout the site, and when a user clicks one, i want the colour to change (like in html when you have a ‘down state’).
Now i want to write a prototype using setRGB that can be referenced by all buttons throughout the site. I also want it work so that when one button is clicked, all other buttons return to their original colour.
Has anyone written a code like this before? I don’t really have any idea about how to write protoypes (i have read everything on kirupa) and need some advice/code.
If you can help, or have a link to a really comprehensive prototype tut, please let me know.
Create 3 Movie clips on the stage that act as buttons. Give them the instance names “button1”, “button2”, and “button3” (no quotes).
Now apply these actions to a frame in the timeline.
[AS]//array to store button instance names
var buttonArray = [“button1”, “button2”, “button3”];
//create the prototype call changeColors
MovieClip.prototype.changeColors = function() {
//create for loop to go through the buttonArray list
for (var i = 0; i<buttonArray.length; i++) {
//create color object that targets each clip in the array
var myColor = new Color(this._parent[buttonArray*]);
//if the instance name in the current position in the array is not equal to this clips name
if (buttonArray* != this._name) {
//set the RGB value to 0x000000 (black)
myColor.setRGB(0x000000);
} else {
//else if it is the same as ths clips name
//set the RGB to 0xFF0000 (red)
myColor.setRGB(0xFF0000);
}
}
};
//onPress is self explanitory
//changeColors is the prototype it calls when you press
button1.onPress = changeColors;
button2.onPress = changeColors;
button3.onPress = changeColors;[/AS]
But with using setRGB keep in mind that the entire clips color changes, so this only works for solid color shapes, so it would be best to have the button label on a layer above the actual movie clip so that doesn’t get changed to the same color. Or you could use setTransform to do more advanced color changes, but I suck with that, so I am not really the one to get into explaining that.
As for OOP, the link Jubba supplied is a great source, but just to warn you… OOP is known for causing migrains… it requires you to sort of change your thought pattern on scripting so it can be a pain if you are used to 1 method. I for one am horrible at OOP because I got used to my method, I really should try harder to learn OOP though :-\
Well… you helped create me, so I don’t see why you are jealous… so it can’t be that… so that really does mean you slapped me because you hate me You created me, now you want to toss me aside!!! :*(