PDA

View Full Version : Components Inside the Window Component


tuor
01-05-2007, 09:45 AM
I have an issue assigning variables to components placed inside the window component when using “window.content”. Does anybody know how to make the following code work?


import mx.managers.PopUpManager;
import mx.containers.Window;

var myWindow:MovieClip = PopUpManager.createPopUp(this, Window, true, {closeButton:false, contentPath:"myMovieclip"});
var myWindowListener:Object = new Object();
myWindowListener.complete = function(evt_obj:Object) {
myWindow.setSize(myWindow.content._width+50, myWindow.content._height+50);
myWindow.content.myLabel.text = "label component"; // this does not work
myWindow.content.myDynamicText.text = "text field"; // this works
};
myWindow.addEventListener("complete", myWindowListener);


Here is the sample fla file for Flash MX 2004:

tuor
01-09-2007, 08:38 AM
OK, I found out what the problem was. Even if I wait until the window is loaded (myWindowListener.complete), the label component instance is not yet ready. I can catch the labels “onLoad” event and then make the changes (this should work for components in general, not just for the label component). Here is the working code:

import mx.managers.PopUpManager;
import mx.containers.Window;

var myWindow:MovieClip = PopUpManager.createPopUp(this, Window, true, {closeButton:false, contentPath:"myMovieclip"});
var myWindowListener:Object = new Object();
myWindowListener.complete = function(evt_obj:Object) {
myWindow.setSize(myWindow.content._width+50, myWindow.content._height+50);
myWindow.content.myLabel.onLoad = function() {
myWindow.content.myLabel.text = "label component"; // this works
}
myWindow.content.myDynamicText.text = "text field"; // this works
};
myWindow.addEventListener("complete", myWindowListener);