0

I have a problem with kinetics object:

I have some kinetics objects...

var trianguloG1 = new Kinetic.Polygon({ 
points: [x, y, catetosTiangulosGrandes+x, y, x, catetosTiangulosGrandes+y, x, y],
fill: '#7e4f00',
draggable: true
});
layer.add(trianguloG1);

Next objects are similar...

Now, I want apply shadow effects in objects (using an array) on click event, but I have an error

var figuras = [ "trianguloG1",
                 "trianguloMediano",
                 "cuadrado",
                 "trianguloPeque1",
                 "trianguloG2",
                 "trianguloPeque2",
                 "paralelogramo1",
                 "paralelogramoEspejo" ];
for(i=0; i<figuras.length; i++) {
    var figurita=figuras[i];
console.log(figurita);
figurita.on('click', function() { //TypeError: figurita.on is not a function
    figurita.setShadowBlur(8);

            //....... more code

Is possible to do this using an array? What is the reason for this error?

VividD
  • 10,456
  • 6
  • 64
  • 111
Gonzacid
  • 1
  • 1
  • Get rid of the quotes, e.g. figuras=[trianguloG1, ... – Guy Sirton Jul 17 '13 at 08:36
  • Ok. Now it's ok but don't work: `var figuras=[trianguloG1,trianguloMediano,cuadrado,trianguloPeque1,trianguloG2,trianguloPeque2,paralelogramo1,paralelogramoEspejo]; for(i=0;i – Gonzacid Jul 17 '13 at 08:58
  • @Gozacid: I think you need to redraw the layer or something along those lines... – Guy Sirton Jul 17 '13 at 08:59
  • layer.draw() I think... The layer is already in your stage right? – Guy Sirton Jul 17 '13 at 09:00
  • yes: `stage.add(layer); ` is included in click event. The problem is only using the array. if I use objects one to one works ok – Gonzacid Jul 17 '13 at 09:06
  • OK. I see what you're saying. I think it has to do with the lambda not being able to see figurita. I'm not really a JS guy was just browsing idly but I think I've seen this. – Guy Sirton Jul 17 '13 at 09:12
  • I think you need to do this extra scope thing along these lines: http://stackoverflow.com/questions/2828718/javascript-scope-problem-when-lambda-function-refers-to-a-variable-in-enclosing – Guy Sirton Jul 17 '13 at 09:13
  • See also here: http://stackoverflow.com/questions/6169313/bind-click-handler-with-variables-in-scope-when-created – Guy Sirton Jul 17 '13 at 09:22
  • Did that make sense? Basically it's about what figurita inside your click function refers to. If the links don't make sense I can try correcting your code... – Guy Sirton Jul 17 '13 at 09:39
  • I can not make it work... – Gonzacid Jul 17 '13 at 09:44
  • solved using this! `for(i=0;i – Gonzacid Jul 17 '13 at 10:01
  • Cool.. Yes, that'll work too. If I were you I'd spend a little time trying to get it work the other way just to get a better understanding of what's going on... – Guy Sirton Jul 17 '13 at 18:29

0 Answers0