我可以从Edge Animate中的click事件中调用console.log吗?

时间:2015-12-18 17:46:53

标签: adobe-edge

我正在尝试找出为什么我的console.log命令在将其放入click事件时抛出事件处理程序错误。

我的Javascript不够好,不知道这是特定于Edge还是更全局的JS。

这是我的代码:

(function($, Edge, compId){
    var Composition = Edge.Composition,
        Symbol = Edge.Symbol; // aliases for  commonly used Edge classes

//Edge symbol: 'stage'
(function(symbolName) {
    Symbol.bindSymbolAction(compId, symbolName, "creationComplete", function(sym, e) {
       // insert code to be run when the symbol is created here
       var want = true;
       console.log(want);
    });

   //Edge binding end

   Symbol.bindElementAction(compId, symbolName, "${Rectangle}", "click", function(sym, e) {
      // insert code for mouse click here
      console.log(want);
   });

  //Edge binding end
})("stage");

//Edge symbol end:'stage'

})(window.jQuery || AdobeEdge.$, AdobeEdge, "EDGE-26284910");

在creationComplete之后的第一个console.log工作正常,点击事件中的下一个不起作用,我不知道为什么。谁能开导我?

由于

1 个答案:

答案 0 :(得分:0)

如果您正确缩进代码,您会注意到want已在内部函数范围内定义,并且无法从单击处理程序中访问。

(function($, Edge, compId){
    var Composition = Edge.Composition,
        Symbol = Edge.Symbol; // aliases for  commonly used Edge classes

//Edge symbol: 'stage'
(function(symbolName) {
    var want;
    Symbol.bindSymbolAction(compId, symbolName, "creationComplete", function(sym, e) {
       // insert code to be run when the symbol is created here
       want = true; //you still can set its value
       console.log(want);
    });

   //Edge binding end

   Symbol.bindElementAction(compId, symbolName, "${Rectangle}", "click", function(sym, e) {
      // insert code for mouse click here
      console.log(want); // but now it is accessible from within this function
   });

  //Edge binding end
})("stage");

//Edge symbol end:'stage'

})(window.jQuery || AdobeEdge.$, AdobeEdge, "EDGE-26284910");