So I’m not a newbie when it comes to actionscript but nor am I an expert. I was wondering if some of you would take the time to guide me a little bit on my Class creating and whatnot. Maybe I’m doing things backwards or just plain bad code - but I’d like to know and learn to better my future code.
Below is my Class…it’s pretty simple.
It uses the drawing api to create a box, a border, and puts an X in the middle of it (text). When rolled over, it should just swap colors. Nothing special.
//Requires Arial Black font to be embedded.
//btnName - the name of the btn to be created.
//nFColor - the fill color for the normal state of the button
//nLColor - the line color for the normal state of the button
//oFColor - the fill color for the over state of the button
//oLColor - the line color for the over state of the button
//boxsize - the width and height of the button.
//closeX - the X coordinate of the button.
//closeY - the Y coordinate of the button.
closeBtn = function (btnName, nFColor, nLColor, oFColor, oLColor, boxsize, closeX, closeY) {
//size of the stroke
var strokesize = boxsize/7;
//container
container = _root.createEmptyMovieClip(btnName, _root.getNextHighestDepth());
//filled box
container.createEmptyMovieClip("cFill", 1);
container.cFill.beginFill(nFColor);
container.cFill.lineStyle(0, nLColor, 0);
container.cFill.moveTo(0, 0);
container.cFill.lineTo(boxsize, 0);
container.cFill.lineTo(boxsize, boxsize);
container.cFill.lineTo(0, boxsize);
container.cFill.lineTo(0, 0);
container.cFill.endFill();
//border
container.createEmptyMovieClip("cBord", 2);
container.cBord.lineStyle(strokesize, nLColor, 100, 0, "none", "none", "round");
container.cBord.moveTo(0, 0);
container.cBord.lineTo(boxsize, 0);
container.cBord.lineTo(boxsize, boxsize);
container.cBord.lineTo(0, boxsize);
//X
container.createEmptyMovieClip("cSymb", 3);
cTF = new TextFormat();
with (cTF) {
size = boxsize-2;
font = "Arial Black";
selectable = 0;
color = nLColor;
}
var metrics = cTF.getTextExtent("X");
var cSymbY = ((boxsize-metrics.textFieldHeight)-(boxsize*.1))/2;
var cSymbX = (boxsize-metrics.textFieldWidth)/2;
container.cSymb.createTextField("my_txt", this.getNextHighestDepth(), cSymbX, cSymbY, metrics.textFieldWidth, metrics.textFieldHeight);
with (container.cSymb.my_txt) {
text = "X";
setTextFormat(cTF);
embedFonts = 1;
}
//placement of the button
container._x = closeX;
container._y = closeY;
//roll over/out functions
container.onRollOver = function() {
myFill = new Color(this.cFill);
myBord = new Color(this.cBord);
mySymb = new Color(this.cSymb);
myFill.setRGB(oFColor);
myBord.setRGB(oLColor);
mySymb.setRGB(oLColor);
};
container.onRollOut = function() {
myFill = new Color(this.cFill);
myBord = new Color(this.cBord);
mySymb = new Color(this.cSymb);
myFill.setRGB(nFColor);
myBord.setRGB(nLColor);
mySymb.setRGB(nLColor);
};
};
myClose = new closeBtn("btn1", 0xB3B6BE, 0xffffff, 0xffffff, 0xB3B6BE, 14, 50, 50);