1

I have a problem, that is I want to use loop to create multiple EventHandlers, but my code shows nothing. What can I do?

    DynamicModule[{i, pos10 = {{}, {}}, pos11 = {{0, 0, 0}, {0, 0, 0}}, 
                   pos12 = {{0, 0, 0}, {0, 0, 0}}, pos20, 
                  pos21 = {{0, 0, 0}, {0, 0, 0}}, pos22 = {{0, 0, 0}, {0, 0, 0}}}, 
 Graphics3D[{

   For[i = 1, i <= 2, i++,
    Print[i]; 
    EventHandler[
     Dynamic[{Translate[Cuboid[], pos11][[i]]},  ImageSize -> Tiny]
     ,
     {"MouseDown" :> {(pos10[[i]] = Mean@MousePosition["Graphics3DBoxIntercepts"])}, 
      "MouseDragged" :> (pos11[[i]] = pos12[[i]] + Mean@MousePosition["Graphics3DBoxIntercepts"] - 
          pos10[[i]]), 
      "MouseUp" :> (pos12 = pos11)}];
    ]},
  PlotRange -> {{-3, 3}, {-3, 3}, {-3, 3}}]]
Kuba
  • 136,707
  • 13
  • 279
  • 740
  • You also need IntroductionToDynamic especially "A good trick to know".
  • – Kuba Nov 24 '14 at 21:58