Search code examples
wolfram-mathematicamathematica-frontend

Mouseover & Dynamic in Mathematica


Could anyone point out why this is not working in Mathematica 8:

DynamicModule[{x = Pink},
 Row[
  {Style["Hello", x],
   Mouseover[
    x = Green; "World",
    x = Blue; "World"]}]]

What I expect is to see the color of "Hello" change when I mouse over "World". What I am getting is a pink "Hello" that never changes color.


Solution

  • A quick check shows that Mouseover evaluates all the expressions inside of it when you first launch it:

    Mouseover[Print["One"]; 1, Print["Two"]; 2]
    

    The idiomatic way of actually making the Mouseover modify the values of x is to use MouseAnnotation. Mr. Wizard's answer describes how to achieve this.