Using jQuery .on('click' to navigate through frames in the timeline by using buttons and the action events wizard
Hi, I've been looking at getting an Animate html project which has been created and published by a member of my team.
I noticed that on debugging, the anonymous functions hooked into click events of buttons were firing more than once.
Basically the project allows navigation through the animate timeline by adding buttons to proceed backward and forward. Our designer use the built in wizards to add click events to buttons. The code the wizard creates looks something like this:
this.frame_10 = function() {
var _this = this;
/* Clicking on the specified symbol instance executes a function. */ _
this.blah2.on('click', function(){
/* Moves the playhead to the specified frame label in the timeline and stops the movie. Can be used on the main timeline or on movie clip timelines. */
_this.gotoAndStop('blah3frame'); });
I noticed that using code similar to this results in the jquery element 'blah2' having the anonymous function added every time we navigate back to frame10.
So, to fix, I hacked the published js to include a removeClick function globally like so:
function removeClick(jqObj) {
if (jqObj == null) return jqObj;
if (jqObj._listeners == null) return jqObj;
jqObj._listeners.click = undefined;
return jqObj;
} and also wrapping the calls to the .on('click' in this function like so:
removeClick(_this.blah2).on('click', function(){ I did read that you should be able to call _this.blah2.off('click') to remove (click) listeners in jQuery, but for some reason this didnt work for me and the number of listeners kept building up...
Anyway, I was wondering if anyone can help with a couple of questions...
Is the above approach correct?
Is there a better way of adding the handlers (easily) preferably still using the wizards?
Is there a way of editing Animate's template wizards code snippets for adding the removeClick function?
Is there a way of editing Animate's master js template to add the removeClick function globally for all future projects?
As you may have guessed, I don't have any experience with Animate (I don't even have it installed)
Thanks for any help.
