javascript - DoubleClick 扩展富媒体横幅广告退出时停止 JS 游戏

标签 javascript html double-click-advertising google-web-designer rich-media

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

请帮忙!我更像是一名设计师而不是编码员,并且花了相当多的时间尝试不同的解决方案...我确信这是一个明显、简单的修复,但我就是看不到它。

提前谢谢您。

相关代码如下:

<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>

我认为我需要的代码将放在此处:

gwd.handleClose_buttonAction = function() {
  // GWD Predefined Function
  gwd.actions.gwdDoubleclick.goToPage('gwd-ad', 'banner-page');

};

最佳答案

处理此问题的最佳方法是通过自定义事件。

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

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

关于javascript - DoubleClick 扩展富媒体横幅广告退出时停止 JS 游戏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33973885/

相关文章:

javascript - 电子邮件验证仅在输入电子邮件但不是有效电子邮件时显示消息

javascript - 使用 Javascript map() 函数返回 JSON 对象的子集

jquery - Socket.io 不改变 HTML

html - 从数据库获取 html 标记并显示在 div 中

html - 居中双击广告

html-email - 如何通过 Double-Click for Publishers 在电子邮件通讯中转换广告?

HTML5 横幅广告 : Clicktag without URL

javascript - Sequelize : Create multiple self association

javascript - 单击时切换多个链接的按钮颜色

html - Bootstrap 3 : Add Buttongroup to navbar