首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在DoubleClick扩展富媒体横幅广告中退出时停止JS游戏

在DoubleClick扩展富媒体横幅广告中退出时停止JS游戏
EN

Stack Overflow用户
提问于 2015-11-29 00:54:11
回答 1查看 346关注 0票数 0

为GWD中的HTML5游戏构建容器,该容器在展开的横幅广告中播放,并且不知道如何在单击退出按钮时停止游戏脚本。例如,即使横幅处于未展开/关闭状态,声音也会在背景中继续播放。

请帮帮我!我更像是一个设计师,而不是一个程序员,我花了相当多的时间尝试不同的解决方案……我确信这是一个显而易见的、简单的解决办法,但我就是看不出来。

提前谢谢你。

相关代码如下:

代码语言:javascript
复制
<script>

function init() {
  canvas = document.getElementById("canvas");
  images = images || {};

  var loader = new createjs.LoadQueue(false);
  createjs.Sound.alternateExtensions = ["mp3"];
  loader.installPlugin(createjs.Sound);
  loader.addEventListener("fileload", handleFileLoad);
  loader.addEventListener("complete", handleComplete);
  loader.loadManifest(lib.properties.manifest);
}

function handleFileLoad(evt) {
  if (evt.item.type == "image") {
    images[evt.item.id] = evt.result;
  }
}

function handleComplete() {
  exportRoot = new lib.PPD_CDW_HyperWiper();

  stage = new createjs.Stage(canvas);
  stage.addChild(exportRoot);
  stage.update();

  createjs.Ticker.setFPS(lib.properties.fps);
  createjs.Ticker.addEventListener("tick", stage);
} 

</script>

<script type="text/javascript" id="gwd-init-code">
(function() {      
  document.body.style.opacity = "0";
  var gwdAd = document.getElementById('gwd-ad');
  /**
   * Handles the DOMContentLoaded event. The DOMContentLoaded event is
   * fired when the document has been completely loaded and parsed.
   */

  function handleDomContentLoaded(event) {
    // This is a good place to show a loading or branding image while
    // the ad loads.
    document.getElementById('loading').style.display = 'block';
  }

  /**
   * Handles the WebComponentsReady event. This event is fired when all
   * custom elements have been registered and upgraded.
   */
  function handleWebComponentsReady(event) {
    document.body.style.opacity = "";


    // Start the Ad lifecycle.
    setTimeout(function() {
      gwdAd.initAd();
    }, 0);
  }

  /**
   * Handles the event that is dispatched after the Ad has been
   * initialized and before the default page of the Ad is shown.
   */
  function handleAdInitialized(event) {
    // This marks the end of the polite load phase of the Ad. If a
    // loading image was shown to the user, this is a good place to
    // remove it.
     document.getElementById('loading').style.display = 'none';
  }

  window.addEventListener('DOMContentLoaded',
    handleDomContentLoaded, false);
  window.addEventListener('WebComponentsReady',
    handleWebComponentsReady, false);
  window.addEventListener('adinitialized',
    handleAdInitialized, false);
  })();
 </script>

下面是我认为我需要的代码:

代码语言:javascript
复制
gwd.handleClose_buttonAction = function() {
  // GWD Predefined Function
  gwd.actions.gwdDoubleclick.goToPage('gwd-ad', 'banner-page');

};
EN

回答 1

Stack Overflow用户

发布于 2015-11-29 01:36:44

处理这种情况的最好方法是通过自定义事件。

从event面板中添加一个新事件。我猜是连接到您附加退出功能的同一点击区域。作为操作,选择自定义代码。在回调函数中,您可以编写自定义代码,这些代码将在用户单击exit按钮时执行。

例如,您可以编写类似createjs.Sound.pause()的代码来暂停声音。请检查createjs API,评估在回调中执行的其他命令。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/33973885

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档