Copy link to clipboard
Copied
Hello,
I've been trying for a few days to get my buttons to link to other pages in my website, but I can't get it to work. Let me explain what my project looks like.
I've got a HTML5 Canvas document, in which I've created an animation. At the end of the animation two buttons appear. I would like to be able to click on these buttons to go to another page inside my website. My buttons are on different layers. I've added the standard HTML5 code snippet, but it doesn't work, not even with the standard adobe.com as URL.
In the console I get this error:
Uncaught TypeError: Cannot read property 'addEventListener' of undefined
at lib.animation.frame_159 (animation.js:836)
at a.b._runActions (createjs-2015.11.26.min.js:17)
at a.b.setPosition (createjs-2015.11.26.min.js:17)
at a.b.setPosition (createjs-2015.11.26.min.js:17)
at lib.animation.c._updateTimeline (createjs-2015.11.26.min.js:14)
at lib.animation.c.advance (createjs-2015.11.26.min.js:14)
at lib.animation.c._tick (createjs-2015.11.26.min.js:14)
at a.b._tick (createjs-2015.11.26.min.js:13)
at a.b.tick (createjs-2015.11.26.min.js:13)
at a.b.update (createjs-2015.11.26.min.js:13)
at a.b.handleEvent (createjs-2015.11.26.min.js:13)
My code looks like this (tipsinfo_btn is the instance name of (one of) my button):
/* Click to Go to Web Page
Clicking on the specified symbol instance loads the URL in a new browser window.
Instructions:
1. Replace http://www.adobe.com with the desired URL address.
Keep the quotation marks ("").
*/
this.tipsinfo_btn.addEventListener("click", fl_ClickToGoToWebPage_5);
function fl_ClickToGoToWebPage_5() {
window.open("http://www.adobe.com", "_blank");
}
-------------------------------------------------------------------------------------------------------------------------
I don't get why tipsinfo_btn is 'undefined', as the console tells me. Because I named it, and added the standard code to it.
I hope there's someone who knows what I'm doing wrong!
Thanks a lot!
Copy link to clipboard
Copied
I'm going to guess that "tipsinfo_btn" does not exist on the same frame you have your code on - so the event listener cannot be added to it.
If your code is at frame 3, for instance, be sure an instance of "tipsinfo_btn" is at frame 3 as well. Even if it exists off-stage on the pasteboard and then shifts into place later on (when you want it visible) that will work.
Copy link to clipboard
Copied
Hello,
Thanks for your answer! Unfortunately, that doesn't fix it. I have my code on the same frame (but another layer?) as my button.
Any other suggestions?
Copy link to clipboard
Copied
Is it the very first frame? If so- have the instance appear on frame 1 and the code on frame 2. Canvas sometimes needs some breathing room...
Copy link to clipboard
Copied
No, it's in frame 90 or something. After the other animations are done, my button starts appearing.
Copy link to clipboard
Copied
Fixed it... it seems you can't have a bitmap as a button...
But thanks for the help!!
Copy link to clipboard
Copied
You can use a bitmap to skin a button - but yeah... you cannot provide an instance name to a bitmap.
Copy link to clipboard
Copied
If you determine the instance name of a bitmap on the stage, you can in fact assign listeners to it.
But yes, it's much easier to just do things properly.
Copy link to clipboard
Copied
But if I have a bitmap and make it a button symbol, it should work, shouldn't it?
I'm a bit confused about it. For now, I've just made my button a vector and that does the trick.
For now, I've just made my button a vector and that does the trick.
But I still don't really get what was going wrong..