Question : Unload window in AS3

Hi all and merry xmas.

I have a problem with a bit of code.
This code basically pops up a window with a textarea and populates it on a button click.
It all works fine but I need to unload it when clicking another button but I cannot seem to get it working.
Anyone knows how to unload it please?

Thanks

Please see code below:
Code Snippet:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
phonebtn.addEventListener(MouseEvent.MOUSE_DOWN, clickHandlerphone);
var PATH:String = "phone_1.txt";
var urlRequest:URLRequest = new URLRequest(PATH);
var urlLoader:URLLoader = new URLLoader();
urlLoader.dataFormat = URLLoaderDataFormat.TEXT; // default
urlLoader.addEventListener(Event.COMPLETE, clickHandlerphone);
urlLoader.load(urlRequest);
 
function clickHandlerphone(eo:MouseEvent):void {
    var myWindow:Sprite = new Sprite();
    var myText:TextArea = new TextArea();
    myText.text = "Hello World!";
	myText.htmlText = urlLoader.data;
	myText.editable = false;
	myText.height = 480;
	myText.width = 645;
	myText.move(125,110);
    myWindow.addChild(myText);
    addChild(myWindow);
}
Open in New Window Select All

Answer : Unload window in AS3

you will need to declare myWindow outside of the function so it has correct scope. This will enable you to remove from within another function.
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
var myWindow:Sprite
function clickHandlerphone(eo:MouseEvent):void {
    myWindow = new Sprite();
    var myText:TextArea = new TextArea();
    myText.text = "Hello World!";
	myText.htmlText = urlLoader.data;
	myText.editable = false;
	myText.height = 480;
	myText.width = 645;
	myText.move(125,110);
    myWindow.addChild(myText);
    addChild(myWindow);
}
 
function btnCloseHandler(e:MouseEvent){
 removeChild(myWindow)
}
Open in New Window Select All
Random Solutions  
 
programming4us programming4us