Actionscript 3 AS3单击其他按钮时卸载外部文件

Actionscript 3 AS3单击其他按钮时卸载外部文件,actionscript-3,button,load,external,Actionscript 3,Button,Load,External,我正在用AS3(Flash)加载这个txt文件,只需点击一个按钮。但是我希望当我点击任何其他按钮时txt消失。我试着停下来;卸下并停止,但它不起作用。有什么想法吗 hello_btn.addEventListener(MouseEvent.CLICK, buttonClick4) function buttonClick4(e:MouseEvent):void { try{ loader_mc.unloadAndStop(); } catch(e:Error) { }

我正在用AS3(Flash)加载这个txt文件,只需点击一个按钮。但是我希望当我点击任何其他按钮时txt消失。我试着停下来;卸下并停止,但它不起作用。有什么想法吗

hello_btn.addEventListener(MouseEvent.CLICK,  buttonClick4)
function  buttonClick4(e:MouseEvent):void
{
     try{
loader_mc.unloadAndStop();
} catch(e:Error) {
}
      var loader:URLLoader;
var info_text:TextField;

CSSFormattingExample();

function CSSFormattingExample():void
{
    info_text = new TextField();
    info_text.wordWrap = true;
    info_text.x = 300;
    info_text.y = 160;
    info_text.width = 800;
    info_text.height = 800;
    addChild(info_text);
}
var url:String = "hello.txt";
var loadit:URLLoader = new URLLoader();
loadit.addEventListener(Event.COMPLETE, completeHandler);
loadit.load(new URLRequest(url));

function completeHandler(event:Event):void
{
    info_text.htmlText = event.target.data as String;
}
}

您首先必须
removeChild()
SWF,否则无法卸载并停止。@Vesper好的,但我应该把它放在哪里?我把它放在任何地方都会出错,你知道吗?您可能已经丢失了指向
loader\u mc
的有效链接,因为我看到您的代码已经有了另外两个加载程序。还有,错误是什么?你应该把
removeChild()
调用放在你的
unloadAndStop()
调用之前,放在
try catch
块中,如果你收到错误,就跟踪它们。是的,你加载了一个文本并希望它消失吗?文本不是MovieClip,您不需要卸载并停止它,您只需使链接无效并更改显示的文本即可卸载它。@Vesper,我该怎么做?