Hi,
I’m in the process of writing a function that will display a dialog box, and return a value determined by which button is pressed. But - I’m a little stuck - and need to rethink my code. So - thought I would ask how you all deal with this problem, as it’s related to a fundamental programming approach that I am having problems with.
I’m struggling with making the transition to nice OOP - and am stuck in some bad procedural ways - so any tips that will improve my general programming practive with respect to this problem will be superb!
I want to be able to call my function like this
my_result = fCustomDialog("please decide", "click OK to continue, CANCEL to abort");
so wrote a function a little like this
function fCustomDialog(sTitle:String, sBody:String):Boolean {
var mcOKCancel:MovieClip = _root.attachMovie("dialog_ok_cancel", "mcOKCancel", 9999);
mcOKCancel.txtTitle.text = sTitle;
mcOKCancel.txtBody.text = sBody;
mcOKCancel.butOK.onRelease = function() {
removeMovieClip(this._parent);
return(true);
}
mcOKCancel.butCancel.onRelease = function() {
removeMovieClip(this._parent);
return(false);
}
}
But - I can’t put the return values inside the onRelease functions of the OK/CANCEL buttons - they’ll never get returned - and the compiler reports this as an error.
So - how should I rewrite my code to be able to call the function like I want to. Any hints as to how I should alter my approach? How do you all do re-usable custom dialog boxes?
Many thanks.