PDA

View Full Version : listening for button clicks INSIDE a window component?


toddclare
04-21-2005, 07:24 PM
I have a window component being used to display a form for the user to input some values.

I want the user to have a SAVE and CANCEL button, which cause the obvious functions to fire.

I can add a listener for the window component's close button, but cant seem to get a hold of listening for the buttons inside the window's content.

help?

Here's the working code for the window's close button:

new_mc.onPress = function() {
var objAddWindowListener:Object = new Object();
objAddWindowListener.click = function(evtObj) {
trace("Window listener click triggered from: " + evtObj.target);
evtObj.target.deletePopUp();
}
objAddWindowListener.complete = function(evtObj) {
trace("Window listener complete triggered from: " + evtObj.target);
addWindow.setSize(addWindow.content._width + 25, addWindow.content._height + 50);
}

var addWindow:MovieClip;
addWindow = mx.managers.PopUpManager.createPopUp(_root, mx.containers.Window, true, {contentPath:"mcnewClassForm", title:"Settings for New Event Class", closeButton:true});
addWindow.addEventListener("click", objAddWindowListener);
addWindow.addEventListener("complete", objAddWindowListener);

This works great.
When i tried to change the .complete listener to:
objAddWindowListener.complete = function(evtObj) {
trace("Window listener complete triggered from: " + evtObj.target);
var myButton:mx.controls.Button = addWindow.content.save_btn;
trace("Button = " + myButton);
addWindow.content.save_btn.addEventListener("click", this);
addWindow.setSize(addWindow.content._width + 25, addWindow.content._height + 50);
}

I never hear the clicks of the buttons.
I also tried to replace the "this" being regisered as the listenr on the green line with "objAddWindowListener" but that failed too...

(By the way, my library linked item "mcnewClassForm" has 2 button components in it -- save_btn and cancel_btn -- those are who I'm hoping to listen for).