Search code examples
actionscript-3flashapache-flexflash-buildermxml

AS3: Alert event firing with no input


I have an alert that pops up when a user clicks on a delete button. However, when the alert is created, it fires the Yes function despite no user input.

Obviously, with a delete button this is bad.

        protected function handleDelete(event:Event): void {
            showAlert();
        }

        private function showAlert():void{
            Alert.yesLabel = "Delete";
            Alert.noLabel = "Cancel";
            Alert.show("Are you sure you want to delete this?", "Confirm Delete", Alert.YES|Alert.CANCEL, this, delete(), null, Alert.CANCEL);
        }

Not sure why, but delete() fires when the alert is created, no matter the input from the user.

Alert is the Flex default alert, no overrides or anything.


Solution

  • delete() shall be without () because you want to pass a reference to it, not to call it and pass return value.