# Custom OK/CANCEL dialog box function

**URL:** <https://forum.kirupa.com/t/custom-ok-cancel-dialog-box-function/281332>\
**Category:** Uncategorized\
**Created:** [February 7, 2009, 6:51pm UTC](https://forum.kirupa.com/t/custom-ok-cancel-dialog-box-function/281332 "2009-02-07T18:51:13Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![slopjockey](https://avatars.discourse-cdn.com/v4/letter/s/58956e/32.png) [@slopjockey](https://forum.kirupa.com/u/slopjockey)\
**Post date:** [February 7, 2009, 6:51pm UTC](https://forum.kirupa.com/t/custom-ok-cancel-dialog-box-function/281332/1 "2009-02-07T18:51:13Z")

</div>

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

```auto
    my_result = fCustomDialog("please decide", "click OK to continue, CANCEL to abort"); 

```

so wrote a function a little like this

```auto
    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.
