在DoubleClick扩展Rich Media横幅广告

时间:2015-11-28 16:54:11

标签: javascript html5 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');

};

1 个答案:

答案 0 :(得分:1)

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

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

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