Method 1:
DynamicModule[{stack, newstack, slide, done = True, last = 0, t},
newstack[s_, k_] /; s == 1 && last != 1 := (If[done,
With[{wd = RandomWord[3],
no = RandomInteger[100, 3],
co = RandomColor[3]},
stack =
Table[Style[Row[{wd[[i]], no[[i]], co[[i]]}, Spacer[6]],
36], {i, 3}]
];
done = False,
done = True];
last = s;
stack[[k]]);
newstack[s_, i_] := (last = s; stack[[i]]);
newstack[1, 1];
slide = Dynamic[
t = Ceiling[Clock[3, 6]]];
Framed[
PaneSelector[{1 -> Dynamic@newstack[t, 1],
2 -> Dynamic@newstack[t, 2], 3 -> Dynamic@newstack[t, 3]}, slide,
Alignment -> Center, ImageSize -> 540]
, FrameMargins -> 40, RoundingRadius -> 5]]
Method 2:
DynamicModule[{stack, newstack, last = 0, t, cycles = 0},
newstack[s_] /; s == 1 && last != 1 := (If[EvenQ[cycles],
With[{wd = RandomWord[3],
no = RandomInteger[100, 3],
co = RandomColor[3]},
stack =
Table[Style[Row[{wd[[i]], no[[i]], co[[i]]}, Spacer[6]],
36], {i, 3}]
]
];
last = s;
++cycles;
stack[[s]]);
newstack[s_] := (last = s; stack[[s]]);
newstack[1];
Framed[
Pane[Dynamic@newstack[Ceiling[Clock[3, 6]]], Alignment -> Center,
ImageSize -> 540]
, FrameMargins -> 40, RoundingRadius -> 5]]
I suppose the key fix here is to put the sildes themselves inside a Dynamic[]
so that they will be updated when there's a change. Another key might be to update the stack in the function that fetches a slides. The reason for it is that you cannot control which Dynamic
is updated first when multiple updates are triggered (as far as I recall). (A change in slide number could cause the stack to change, perhaps triggering an update of the slide on screen again both before and after the new stack is computed, a fraction of a second apart.)
Another method would be to let the clock run forever (Clock[Infinity]
) and use Mod
and Ceiling
to map to slide number. Then the value of the clock can be used to determine when it's time to change the stack.