alwayzambitious Posted May 11, 2015 Share Posted May 11, 2015 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 somethingthanks 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 readinghttp://www.goodboydi...ts-interactive/How would do I do what i asked before.. Quote Link to comment Share on other sites More sharing options...
clement_cvL Posted May 11, 2015 Share Posted May 11, 2015 Hey, it's funny because I had to do it today... I would to like this :btn.click = noop.bind(undefined, btn)var noop = function(bt){ console.log(bt);}I'm not sure for the first parameter being undefined, let me know Quote Link to comment Share on other sites More sharing options...
dimumurray Posted May 11, 2015 Share Posted May 11, 2015 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... Quote Link to comment Share on other sites More sharing options...
alwayzambitious Posted May 11, 2015 Author Share Posted May 11, 2015 dimmurray can you post an example where u pass function noop an argument, that was my op, i know about setting interactive to true and about on (click, noop) but i dont know how to parameters to the nooop. Thanks.clement i will give your example a shot and report back Quote Link to comment Share on other sites More sharing options...
clement_cvL Posted May 11, 2015 Share Posted May 11, 2015 I just tested for you and it works:var graphics = new PIXI.Graphics();graphics.interactive = true;graphics.mousedown = onTouchstart.bind(undefined, "test");function onTouchstart(param, e) { console.log(param, e); // test, Object{}} Quote Link to comment Share on other sites More sharing options...
alwayzambitious Posted May 12, 2015 Author Share Posted May 12, 2015 Hey clement, thanks for taking the extra step and testing it for me . It does work now!! I can resume building my site. I'm shedding a tear and maybe those other posters who had the same question hopefully would find this answer. Thank you everyone. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.