Flash Type:
Application using forms.
Flash Version:
Flash MX 2004 Professional.
Components Used:
Menu
Window
Alert
Combo Box
Label
Text Field
Radio Button
Check Box
Problem Area:
A Window Launched by the menu has a close button. The close button’s Listener doesn’t work.
Code Explanation with problem:
The Menu is created during run time.
The listener function in menu when clicked, calls a user defined function launchWindow();
The launchWindow(); creates the Window with content path frmCalculator and has the close button .
After calling the launchWindow(); the Window with frmCalculator is loaded.
But when the close button is clicked the myWindow.addEventListener(“click” , windowListener); is not working, and hence the
windowListener.click = function() is not called at all.
But if the launchWindow(); is called directly during loading the close button event works.
I have attached the source code. Please help me.
//Source Code========================================
import mx.controls.Menu;
import mx.controls.MenuBar;
import mx.controls.Alert;
import mx.managers.PopUpManager;
import mx.containers.Window;
//launchWindow(“frmCalculator”,“Form Calculator”,771, 531.5,15,33.7); //When this is used the close button works !!!
//Message Box Function
function msgBox(msgContent,msgTitle){
Alert.show(msgContent, msgTitle, Alert.OK, this, myClickHandler, “stockIcon”, Alert.OK);
}
//Window Launcher Function
//Arguments:
//dataTitle: Title for the window
//dataContent: the frmCalculator which is the second screen next to the first application created.
//closeButton: true
function launchWindow(dataContent,dataTitle,dataSX,dataSY,dataX,dataY){
myWindow = PopUpManager.createPopUp (_root, Window, false, {title:dataTitle, contentPath:dataContent, closeButton:true });
myWindow.setSize(dataSX,dataSY);
myWindow._x=dataX;
myWindow._y=dataY;
focusManager.setFocus(myWindow);
}
//Listener function for close button
//This listener doesn’t work when the launchWindow() is called from the MENU Component.
//But this listener works when the launchWindow() is called directly during load.
windowListener=new Object();
windowListener.click = function(){
trace(“Close”);
myWindow.deletePopUp();
}
myWindow.addEventListener(“click” , windowListener);
//Run Time Menu Creation
// instances on the stage
var menuBar:MenuBar;
// variables in this script
var manager_menu:Menu;
/=================
MANAGER MENU
=================/
//Main Menu
manager_menu = menuBar.addMenu(“Manager”);
//Sub Menu
manager_menu.addMenuItem({label:“Calculator”, instanceName:“calculatorInstance”, icon:“new”});
manager_menu.addMenuItem({label:“Exit”, instanceName:“exitInstance”});
// The listenered for the manager menu (and submenus)
var managerListener:Object = new Object();
managerListener.change = function(eventObj : Object) : Void {
//selected_ta = "Selected Application: " + eventObj.menuItem.attributes.label;
//msgBox(selected_ta,“Alert: Manager”);
//statusBar.text=selected_ta;
//barProgress.setProgress(100,100);
//launchWindow(frmCalculator,“frmCalculator”,“Form Calculator”,771, 531.5,15,33.7);
switch (eventObj.menuItem) {
//When this code calls the launchWindow(); the close button in the window doesn't work at all. The " myWindow.addEventListener("click" ,
windowListener); " is not working !!!
case eventObj.menu.calculatorInstance: launchWindow(“frmCalculator”,“Form Calculator”,771, 531.5,15,33.7); break;
case eventObj.menu.exitInstance: fscommand(“quit”); break;
}
}
// register the listeners with the separate menus
manager_menu.addEventListener(“change”, managerListener);
Code========================================