macsym
07-13-2004, 02:32 PM
Hi everybody,
I am trying to launch an alert from a menu bar, unfortunately, it doesn't work.
I can launch an alert from a button with this code:
on (click) {
import mx.controls.Alert;
myClickHandler = function (evt) {
if (evt.detail == Alert.OK) {
trace("OK was clicked");
}
};
Alert.show("message in the alert", "title", Alert.OK | Alert.CANCEL, this, myClickHandler);
}
But when I paste the exact same code in my menuBar, it doesn’t work. Here is the code:
var menu_settings = mainMenuBar.addMenu("Settings");
menu_settings.addMenuItem({label:"Default settings", instanceName:"default_settings_instance"});
var link_settings_listener = new Object();
link_settings_listener.change = function(evt) {
var menu = evt.menu;
var item = evt.menuItem;
if (item == menu.default_settings_instance) {
import mx.controls.Alert;
myClickHandler = function (evt) {
if (evt.detail == Alert.OK) {
trace("OK was clicked");
}
};
Alert.show("message in the alert", "title", Alert.OK | Alert.CANCEL, this, myClickHandler);
}
};
menu_settings.addEventListener("change", link_settings_listener);
The error message is “Failed to create a new alert, probably because there is no Alert in the Library”. Of course, I have the alert component in my library!
Any idea?
Thanks in advance,
Macsym
I am trying to launch an alert from a menu bar, unfortunately, it doesn't work.
I can launch an alert from a button with this code:
on (click) {
import mx.controls.Alert;
myClickHandler = function (evt) {
if (evt.detail == Alert.OK) {
trace("OK was clicked");
}
};
Alert.show("message in the alert", "title", Alert.OK | Alert.CANCEL, this, myClickHandler);
}
But when I paste the exact same code in my menuBar, it doesn’t work. Here is the code:
var menu_settings = mainMenuBar.addMenu("Settings");
menu_settings.addMenuItem({label:"Default settings", instanceName:"default_settings_instance"});
var link_settings_listener = new Object();
link_settings_listener.change = function(evt) {
var menu = evt.menu;
var item = evt.menuItem;
if (item == menu.default_settings_instance) {
import mx.controls.Alert;
myClickHandler = function (evt) {
if (evt.detail == Alert.OK) {
trace("OK was clicked");
}
};
Alert.show("message in the alert", "title", Alert.OK | Alert.CANCEL, this, myClickHandler);
}
};
menu_settings.addEventListener("change", link_settings_listener);
The error message is “Failed to create a new alert, probably because there is no Alert in the Library”. Of course, I have the alert component in my library!
Any idea?
Thanks in advance,
Macsym