【问题标题】:addChild and removeCurrent childaddChild 和 removeCurrent 孩子
【发布时间】:2018-03-09 04:31:13
【问题描述】:

我有多个按钮可以加载多个影片剪辑。我的问题是,当一个加载时它不会消失,阻止其他人在单击按钮时加载。下面是我的代码。我需要添加和“if”语句吗?任何帮助将不胜感激。谢谢。

movieButton.addEventListener(MouseEvent.CLICK, gotoMovie);
webButton.addEventListener(MouseEvent.CLICK, gotoWeb);
mailButton.addEventListener(MouseEvent.CLICK, gotoMail);

 function gotoMovie(event:Event):void {
    var moviescene:MovieClip = new movie();
    stage.addChild(moviescene);

}

function gotoWeb(event:Event):void {
    var webscene:MovieClip = new web();
    stage.addChild(webscene);

}

function gotoMail(event:Event):void {
    var contactscene:MovieClip = new contact();
    stage.addChild(contactscene);

}

【问题讨论】:

  • 如果您标记您正在使用的语言会有所帮助。
  • 哎呀!谢谢。

标签: actionscript-3 removechild addchild


【解决方案1】:

我不完全确定你想要实现什么,但我想这应该会有所帮助。

var currentScene:MovieClip; // pointer to scenes
movieButton.addEventListener(MouseEvent.CLICK, gotoMovie);
webButton.addEventListener(MouseEvent.CLICK, gotoWeb);
mailButton.addEventListener(MouseEvent.CLICK, gotoMail);

// function that sets new scenes
function setScene(mc:MovieClip):void {
    if(currentScene) stage.removeChild(currentScene);// if a scene is already loaded, remove it
    currentScene = mc; // set currentScene to new scene
    stage.addChild(currentScene); // add it to stage
}

function gotoMovie(event:MouseEvent):void {
    setScene(new movie());
}

function gotoWeb(event:MouseEvent):void {
    setScene(new web());
}

function gotoMail(event:MouseEvent):void {
    setScene(new contact());
}

【讨论】:

  • 非常感谢您!我已合并您的脚本,现在收到错误消息。您的代码中的某些内容与我当前在文件中的某些代码冲突。现在正在经历。再次感谢您。
猜你喜欢
  • 2011-05-11
  • 2011-02-23
  • 1970-01-01
  • 1970-01-01
  • 2020-07-29
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多