2 Replies Latest reply on Jul 3, 2014 10:29 PM by Tim. Signore

    Acessing event targets

    Tim. Signore Level 1

      Hello,

      I am trying to create a row of four buttons, which input user responses (1-4). I have made each button a symbol with a two-state timeline, as I want them to change to give touch feedback. I have coded one of the buttons, and it responds as i wish, and logs a value, which i have attached to it as a variable called value. All of the buttons will have a class of "buttons", and I realise that the clever way to do this would be to attach one touch event to all symbols with that class, and then use the event.target to return the relevant value. It is the retrieval of the event target that stumps me; I have tried many ways but always get undefined. Not sure if this is to do with Edge adding "Stage_" to the beginning of the symbol name?

       

      It also confuses me, as if i want to delete a symbol in response to a button within that symbol being clicked, i can use "sym.deleteSymbol();", but when I use sym.getVariable("value") it does not work.

       

      A link to what I've done so far is below.

      Thanks in advance for all help,

      Tim

       

       

      ButtonsTest.zip - Box

        • 1. Re: Acessing event targets
          Tim. Signore Level 1

          I have done some further investigating on the above, and I have distilled my problem to these factors:

           

          1) I want to target a set of buttons simultaneously with one touchstart  event handler. The buttons are symbols, so that their timeline can effect a visual change in response to touch. I can assign a class to the symbols to target them, but it is the symbol elements, not the symbols themselves that receive the touchstart event.

           

          2) Each of the set of buttons will generate a value (1-4), which i can attach to the symbols as a variable called "value".

           

          So in total: how do I listen for a touchstart event collectively on a set of symbols' elements, respond to them as individual event targets and access the event target's parent symbol to play the timeline and retrieve the variable "value".

           

          Or, am I being dense and there's a far easier way to do this.

          Many thanks,

          Tim

          • 2. Re: Acessing event targets
            Tim. Signore Level 1

            I have a partial solution, which I'm posting, in case it helps anyone else out. I have been able to target the whole set of buttons by nesting them all in another symbol, looping through it's children, and adding a class to each of the symbol elements (see below). The part that still flumoxes me is how to then reference the symbol itself from the symbol element, which is returned as the e.currentTarget.

             

            I have posted the project files here:

            ButtonsTest2.zip - Box

             

            Would really appreciate a hand with this - it's driving me round the bend.

            Many thanks,

            Tim

             

            var btn1 = sym.getSymbol("allButtons").getSymbol("Button1");

            var btn2 = sym.getSymbol("allButtons").getSymbol("Button2");

             

            btn1.setVariable("value",1);

            btn2.setVariable("value",2);

             

            var buttons = sym.getSymbol("allButtons").getChildSymbols();

            for (var i=0; i<buttons.length; i++){

              var current = buttons[i].getSymbolElement();

              current.addClass("btnClicka");

            }

             

            $(".btnClicka").on("click", function(e){

              console.log("click");

              //The below does not work - I have tried every combination I can think of to target the symbol from the event target, getParentSymbol(), etc.

              sym.$(e.currentTarget).parent().stop("Touch");

              //The below does work, proving that it is the targetting that is at fault

              //btn1.stop("Touch");

            });

            1 person found this helpful