10 Replies Latest reply on Nov 20, 2014 2:54 AM by vivekuma

    bindTriggerAction Post Update (10/7/14)

    RDPlante

      Before updating to the new Edge version, I would systematically go through the various labels and add timeline based triggers via:

      if (sym.timelines["Default Timeline"].labels) {
          $.each(sym.timelines["Default Timeline"].labels, $.proxy(function(label, pos) {
              if (label.indexOf("trigger_") === 0) {
                  modified = true;
      
      
                  modFunc = $.proxy(function() {
                      this.trigger({
                          name: "symbolEvent",
                          label: label.substr(8)
                      });
                  }, this);
      
      
                  modSym.bindings.push(modFunc);
      
      
                  AdobeEdge.Symbol.bindTriggerAction(GPA.compId, sym.options.data.typeName, "Default Timeline", pos, modFunc);
              }
          }, this));
      }
      

       

      The new way of doing this is nearly identical, yet somehow fails to bind all but the last of requested bindings:

      var symLabels = sym.data[symName].timeline.labels,
          modSym = {
              bindings: [],
              sym: sym
          },
          modified = false,
          i, listLength, label, modFunc,
          subSyms = sym.ci;
      
      
      if (symLabels) {
          $.each(symLabels, $.proxy(function(label, pos) {
              if (label.indexOf("trigger_") === 0) {
                  modified = true;
      
      
                  modFunc = $.proxy(function() {
                      this.trigger({
                          name: "symbolEvent",
                          label: label.substr(8)
                      });
                  }, this);
      
      
                  modSym.bindings.push(modFunc);
      
      
                  AdobeEdge.Symbol.bindTriggerAction(GPA.compId, symName, "Default Timeline", pos, modFunc);
              }
          }, this));
      }
      

       

      The results should be the same, but none of the bindings seem to fire, and worse, any bindings put on via the timeline in Edge seem to be removed entirely.

        • 1. Re: bindTriggerAction Post Update (10/7/14)
          DavePowellGPA

          I'd like to hear some feedback on this one quickly as well. Another update of Edge Animate has broken elements in play again. Hopefully a minor oversight that can be quickly resolved!

          • 2. Re: bindTriggerAction Post Update (10/7/14)
            Vinod Menon@Adobe Adobe Employee

            Hi Robert

             

            Thanks for sharing the code snippet. We will check out from our side and try to repro this issue.

             

            Regards

            Vinod

            • 3. Re: bindTriggerAction Post Update (10/7/14)
              Bharadwaj Level 2

              Hi Robert,

              Can you share a sample file you have used this snippet and it is working in the older version of edge animate.

              • 4. Re: bindTriggerAction Post Update (10/7/14)
                vivekuma Adobe Employee

                Hi Robert,

                 

                1. Can you tell us how you are getting symName?

                2. Can you preview the composition in the browser, and open the developer tool of the browser and see the console if any error has been thrown and share the console messages?

                 

                Regards,

                Vivkeuma

                • 5. Re: Re: bindTriggerAction Post Update (10/7/14)
                  RDPlante Level 1

                  Here are all the relevant functions from our symbol widget:

                      onRender: function() {
                          var sym = this.symbol;
                  
                  
                          if (!sym) {
                              sym = this.stage.createChildSymbol(this.name, "Stage");
                  
                  
                              if (sym) {
                                  var elem = sym.getSymbolElement();
                  
                  
                                  if (sym.options) {
                                      this.autoPlay = sym.options.data.timelines["Default Timeline"].autoPlay;
                                  } else {
                                      this.autoPlay = sym.autoPlay;
                                  }
                  
                  
                                  this.element = elem;
                                  this.symbol = sym;
                              } else {
                                  this.trigger({
                                      name: "error",
                                      errorType: "symbol(s) could not be created"
                                  });
                                  console.error('Could not find symbol with name ' + this.name);
                                  return;
                              }
                          } else if (this.persistent) {
                              return;
                          }
                  
                  
                          $.each(this.params, $.proxy(function(key, value) {
                              sym.setVariable(key, value);
                          }, this));
                  
                  
                          sym.stop(0);
                      },
                      onPostRender: function() {
                          var sym = this.symbol;
                  
                  
                          if (!sym) {
                              return;
                          }
                  
                  
                          if (!this.hasTriggers) {
                              this.enableTriggers(sym);
                          }
                  
                  
                          this.hasTriggers = true;
                  
                  
                          if (this.autoPlay) {
                              sym.play(0);
                  
                  
                              if (this.persistent) {
                                  this.autoPlay = false;
                              }
                          }
                      },
                      enableTriggers: function(sym) {
                          if (sym.options) {
                              this.enableOldTriggers(sym);
                          } else {
                              this.enableNewTriggers(sym);
                          }
                      },
                      enableOldTriggers: function(sym) {
                          var procSyms = this.processed;
                  
                  
                          for (var i = 0, numMod = procSyms.length; i < numMod; i++) {
                              if (procSyms[i].options.data.typeName === sym.options.data.typeName) {
                                  return;
                              }
                          }
                  
                  
                          var modSym = {
                              bindings: [],
                              sym: sym
                          };
                          var modified = false;
                          var modFunc;
                  
                  
                          if (sym.timelines["Default Timeline"].labels) {
                              $.each(sym.timelines["Default Timeline"].labels, $.proxy(function(label, pos) {
                                  if (label.indexOf("trigger_") === 0) {
                                      modified = true;
                  
                  
                                      modFunc = $.proxy(function() {
                                          this.trigger({
                                              name: "symbolEvent",
                                              label: label.substr(8)
                                          });
                                      }, this);
                  
                  
                                      modSym.bindings.push(modFunc);
                  
                  
                                      AdobeEdge.Symbol.bindTriggerAction(GPA.compId, sym.options.data.typeName, "Default Timeline", pos, modFunc);
                                  }
                              }, this));
                          }
                  
                  
                          if (modified) {
                              this.modifiedSymbols.push(modSym);
                          }
                  
                  
                          if (sym.aSymbolInstances) {
                              $.each(sym.aSymbolInstances, $.proxy(function(index, id) {
                                  this.enableOldTriggers(sym.getSymbol(sym.idLookup[id]));
                              }, this));
                          }
                  
                  
                          this.processed.push(sym);
                      },
                      enableNewTriggers: function(sym) {
                          var procSyms = this.processed,
                              symName = sym.name;
                  
                  
                          for (var i = 0, numMod = procSyms.length; i < numMod; i++) {
                              if (procSyms[i].name === symName) {
                                  return;
                              }
                          }
                  
                  
                          var symLabels = sym.data[symName].timeline.labels,
                              modSym = {
                                  bindings: [],
                                  sym: sym
                              },
                              modified = false,
                              i, listLength, label, modFunc,
                              subSyms = sym.ci;
                  
                  
                          if (symLabels) {
                              $.each(symLabels, $.proxy(function(label, pos) {
                                  if (label.indexOf("trigger_") === 0) {
                                      modified = true;
                  
                  
                                      modFunc = $.proxy(function() {
                                          this.trigger({
                                              name: "symbolEvent",
                                              label: label.substr(8)
                                          });
                                      }, this);
                  
                  
                                      modSym.bindings.push(modFunc);
                  
                  
                                      AdobeEdge.Symbol.bindTriggerAction(GPA.compId, symName, "Default Timeline", pos, modFunc);
                                  }
                              }, this));
                          }
                  
                  
                          if (modified) {
                              this.modifiedSymbols.push(modSym);
                          }
                  
                  
                          if (subSyms) {
                              for (i = 0, listLength = subSyms.length; i < listLength; ++i) {
                                  this.enableNewTriggers(subSyms[i]);
                              }
                          }
                  
                  
                          this.processed.push(sym);
                      },
                      onCleanup: function() {
                          if (!this.symbol) {
                              return;
                          }
                  
                  
                          var modifiedSymbols = this.modifiedSymbols,
                              numModSyms = modifiedSymbols.length,
                              i, modSym, sym, oldSym, boundFuncs, symBindings,
                              j, boundFunc,
                              k, bindID, funcQuery;
                  
                  
                          for (i = 0; i < numModSyms; ++i) {
                              modSym = modifiedSymbols[i];
                              sym = modSym.sym;
                              oldSym = sym.options,
                              boundFuncs = modSym.bindings;
                              symBindings = oldSym ? sym.options.data.bindings : sym.data[sym.name].bindings;
                  
                  
                              for (j = boundFuncs.length -1; j > -1; --j) {
                                  boundFunc = boundFuncs[j];
                  
                  
                                  for (k = symBindings.length - 1; k > -1; --k) {
                                      bindID = oldSym ? symBindings[k] : symBindings[k][1];
                                      funcQuery = sym[bindID];
                  
                  
                                      if (funcQuery === boundFunc) {
                                          delete sym[bindID];
                  
                  
                                          boundFuncs.splice(j, 1);
                                          symBindings.splice(k, 1);
                  
                  
                                          break;
                                      }
                                  }
                              }
                          }
                  
                  
                          this.modifiedSymbols = [];
                          this.processed = [];
                      },
                      onDestroy: function() {
                          this.symbol.deleteSymbol();
                  
                  
                          delete this.symbol;
                      }
                  
                  • 6. Re: bindTriggerAction Post Update (10/7/14)
                    vivekuma Adobe Employee

                    Did you check the console messages for any error, as we can't debug the code unless you share the whole composition?

                    • 7. Re: bindTriggerAction Post Update (10/7/14)
                      RDPlante Level 1

                      There were no errors. The code above seemed to be functioning properly, and the Edge project showed no "Error in Timeline Action" type errors either.

                       

                      All that I saw was that none of the original bindings fired anymore, and only the last bindTriggerAction applied worked at all.

                       

                      Steps to reproduce would be:

                      Create a new project.

                      Create several symbols with actions on their timelines, and a variety of labels, some of which with "trigger_" prepended to them.

                      In the creationComplete event on the main stage instantiate a few symbols.

                      For each of those symbols, use the enableTriggers function, replacing this.trigger above with a console.log statement.

                      You will probably need to adjust the convention as the code is from an object based model, rather than a functional based one.

                       

                      If you are in the older Animate, you would see that all the inserted log statements will fire correctly, whereas in the new project, they do not.

                       

                      A simpler test than this would be to simply bind multiple trigger actions to a generated symbol's timeline at random places, and see if they all fire. If so, then this issue may be merely a red herring.

                      • 8. Re: bindTriggerAction Post Update (10/7/14)
                        vivekuma Adobe Employee

                        Hi Robert,

                         

                        Yes, I can reproduce the issue.

                        This is a bug in the functionality of bindTriggerAction function, which is triggering only the last action bound.

                         

                        We will fix this issue in the upcoming release.

                         

                        Regards,

                        Vivekuma

                        • 9. Re: Re: bindTriggerAction Post Update (10/7/14)
                          RDPlante Level 1

                          Excellent, thank you.

                           

                          Would it also be possible, by chance, to provide a set of functions to remove triggers, much in the way jQuery does? This comes up in our code a fair bit, and right now I end up doing something a little unwieldy, namely:

                              onCleanup: function() {
                                  if (!this.symbol) {
                                      return;
                                  }
                          
                          
                                  var modifiedSymbols = this.modifiedSymbols,
                                      numModSyms = modifiedSymbols.length,
                                      i, modSym, sym, oldSym, boundFuncs, symBindings,
                                      j, boundFunc,
                                      k, bindID, funcQuery;
                          
                          
                                  for (i = 0; i < numModSyms; ++i) {
                                      modSym = modifiedSymbols[i];
                                      sym = modSym.sym;
                                      oldSym = sym.options,
                                      boundFuncs = modSym.bindings;
                                      symBindings = oldSym ? sym.options.data.bindings : sym.data[sym.name].bindings;
                          
                          
                                      for (j = boundFuncs.length -1; j > -1; --j) {
                                          boundFunc = boundFuncs[j];
                          
                          
                                          for (k = symBindings.length - 1; k > -1; --k) {
                                              bindID = oldSym ? symBindings[k] : symBindings[k][1];
                                              funcQuery = sym[bindID];
                          
                          
                                              if (funcQuery === boundFunc) {
                                                  delete sym[bindID];
                          
                          
                                                  boundFuncs.splice(j, 1);
                                                  symBindings.splice(k, 1);
                          
                          
                                                  break;
                                              }
                                          }
                                      }
                                  }
                          
                          
                                  this.modifiedSymbols = [];
                                  this.processed = [];
                              },
                          
                          • 10. Re: bindTriggerAction Post Update (10/7/14)
                            vivekuma Adobe Employee

                            The patch (EA 2014.1.1) with the fix is live now.


                            Regards,

                            Vivekuma

                            Edge Animate Team

                            1 person found this helpful