Question
Scope of variable in event handler
function showAlert(num):Boolean {
var ret:Boolean;
var myClickHandler = function (evt) {
if (evt.detail == mx.controls.Alert.OK){
ret = true;
} else {
ret = false;
}
}
alert("Only " + num + " of this item are available. Click OK to buy
these.", "Availability", mx.controls.Alert.OK |
mx.controls.Alert.CANCEL, myClickHandler);
return ret;
}
if (showAlert(totavail)) {//etc.
Why is it that the value of ret set in the event handler is not the same
as ret in the main function which remains undefined?
What is the correct way to write this??
Doug
var ret:Boolean;
var myClickHandler = function (evt) {
if (evt.detail == mx.controls.Alert.OK){
ret = true;
} else {
ret = false;
}
}
alert("Only " + num + " of this item are available. Click OK to buy
these.", "Availability", mx.controls.Alert.OK |
mx.controls.Alert.CANCEL, myClickHandler);
return ret;
}
if (showAlert(totavail)) {//etc.
Why is it that the value of ret set in the event handler is not the same
as ret in the main function which remains undefined?
What is the correct way to write this??
Doug