//aha
/*PARAMETERS
pMsgString - message String
pDepth - depth of messageBox in _root
pBtnObjArray - an array with "button objects"
example: [label:"myString",action:myfunction(){...}]
or
[label:"myString",action:"functionName",target:"object where to execute function"]
pX , pY [optional] - where to create messageBox on stage
*/
_global.createMessageBox = function (pMsgString, pDepth, pBtnObjArray,pX,pY) {
// Main-Mc...
var mc =_root.createEmptyMovieClip("messageBox_mc", pDepth);
//maybe usefull..
// onCreateMessageBox();
//remove MessageBox-function
mc.removeMessageBox = function() {
this.removeMovieClip();
// onRemoveMessageBox();
}
//
//Message-TextField...
var msg_textformat = new TextFormat();
msg_textformat.font = "_sans";
msg_textformat.size = 12;
//
mc.createTextField("msg_txt", 1, 0, 0, 200, 200);
mc.msg_txt.background = true;
//mc.msg_txt.border = true;
mc.msg_txt.autoSize = true;
mc.msg_txt.html = true;
mc.msg_txt.htmlText = pMsgString;
mc.msg_txt.setTextFormat(msg_textformat);
//
//Buttons...
for(var i = 0;i<pBtnObjArray.length;++i) {
var cBtn = mc.createEmptyMovieClip("btn"+i+"_mc", i+2);
//set _y position of button
cBtn._y = mc.msg_txt._height+5;
//TODO: center buttons in messageBox, unternanderstelling of buttons in messageBox
if(i>0) {
cBtn._x += lastCreatedButton._x+lastCreatedButton._width+5;
}
//
cBtn.createTextField("btn_txt", 1, 0, 0, 5, 5);
//
cBtn.btn_txt.autoSize = true;
cBtn.btn_txt.selectable = false;
// cBtn.btn_txt.border = true;
cBtn.btn_txt.html = true;
cBtn.btn_txt.htmlText = pBtnObjArray[i].label;
btn_textformat = mc.msg_txt.getTextFormat();
cBtn.btn_txt.setTextFormat(btn_textformat);
//
var txtWidth = cBtn.btn_txt._width;
var txtHeight = cBtn.btn_txt._height;
//using color parameter, otherwise using default color
var btnCol = (pBtnObjArray[i].color == undefined) ? 0xcccccc : pBtnObjArray[i].color;
cBtn.beginFill(btnCol);
cBtn.lineStyle(5,btnCol);
cBtn.lineTo(txtWidth, 0);
cBtn.lineTo(txtWidth, txtHeight);
cBtn.lineTo(0, txtHeight);
cBtn.lineTo(0, 0);
cBtn.endFill();
//
cBtn.onRollOver = function() {
this._alpha = 70;
};
cBtn.onRollOut = function() {
this._alpha = 100;
};
//setting button action..
//save index in btn
cBtn.actIndex = i;
var btnAction;
if(pBtnObjArray[i].action == undefined) {
btnAction = function() {
mc.removeMessageBox();
trace("MessageBox - default action: remove MessageBox "+mc);
}
} else if(pBtnObjArray[i].target !== undefined) {
//trace("target is definied");
btnAction = function() {
//save action and target temporary, then remove messageBox and call action in target..
var fnc = pBtnObjArray[this.actIndex].target[pBtnObjArray[this.actIndex].action]
var trg = pBtnObjArray[this.actIndex].target;
mc.removeMessageBox();
fnc.apply(trg);
}
} else if (typeof pBtnObjArray[i].action == "function"){
btnAction = function() {
var fnc = pBtnObjArray[this.actIndex].action;
mc.removeMessageBox();
fnc();
};
} else {
trace("WARNING - MessageBox - could not define action for button: "+cBtn);
}
cBtn.onRelease = btnAction;
//only for setting position of buttons
var lastCreatedButton = cBtn;
}
//
//Draw a line around all of it..
var mcHeight = mc._height+5;
var mcWidth = mc._width+5;
mc.moveTo(-10,-10);
mc.lineStyle(5,0xCFCFCF);
mc.beginFill(0xfcfcfc);
mc.lineTo(mcWidth, -10);
mc.lineTo(mcWidth, mcHeight);
mc.lineTo(-10, mcHeight);
mc.lineTo(-10, -10);
mc.endFill();
//
//Align / set position of MessageBox
if(pX !== undefined) {
mc._x = pX;
} else {
//align box in center of Stage
mc._x = Stage.width/2 - mc._width/2;
}
if(pY !== undefined) {
mc._y = pY;
}else {
//align box in center of Stage
mc._y= Stage.height/3 - mc._height/2;
}
//return reference to messageBox
return mc;
};
// //
/*//usage
#include "createMessageBox.as"
//----
obj = {nm:"hello this is 'obj.nm'"};
obj.jepp = function() {
trace("jepp");
trace(this.nm);
createMessageBox("Wollen Sie wirklich wirklich?", 1, [{label:"Ja, sicher!", color:0xA9DC98, action:function () {
createMessageBox("ENDE", 1, [{label:"ok", action:function () { trace("ende");}}]);
}}, {label:"Nein, ich hab's mir nochmal überlegt.", color:0xFC8274}]);
};
createMessageBox("Wollen Sie wirklich?", 1, [{label:"Ja!", action:"jepp", target:obj, color:0xA9DC98}, {label:"Nein!", color:0xFC8274}]);
*/