Jump to content

how to tell which button was clicked using PIXI.js


alwayzambitious
 Share

Recommended Posts

Hi. I figured I would move the post here in the general section... 


 


I have three buttons that i want to give the same function too (noop)...



btn3Graph.on('click', noop)
function noop(event) {
console.log(event.data.target);
};

When I trace event.data.target I get null but i really want the name btn3Graph, 


because depending on the button click it will do a different action..


 


event.data.originalEvent.target  results in the html canvas or the dom element, which makes sense 


because pixi runs on canvas but what about the sprites and movieclips within Pixi


 


Update: 


event.data.originalEvent.target returns html canvas element but in the docs here 


http://pixijs.github...actionData.html it says its supposed to return sprite. Maybe Im missing something


thanks in advance


 


One thing i forgot to mention that would help you help me... The goal is to have one function that is the callback for all my buttons, and within it i have a case statement that determines what code to run depending on which button was clicked... orrr should i scrap that i idea and have different functions...I am thinking in terms of actionscript 3 by the way... 


 


and...


 


after reading


http://www.goodboydi...ts-interactive/


How would do I do what i asked before..


Link to comment
Share on other sites

It looks like all you need to do is set the interactive property on your sprite instance to true...like so:

btn3Graph.interactive = true;btn3Graph.on('click', noop);function noop(event) {   ...}

Better yet you could bind the click handler directly to the stage instance and handle all your click events there...

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...