4
$\begingroup$

Why does

DynamicModule[{grf, x}, 
 Panel[{Button["Export", Export["test.png", grf]], 
   Slider[Dynamic[x], {1, 4}], 
   grf = Dynamic[Graphics[{Line[{{1, x}, {x, 1}, {3, 2}}]}]]}]]

export properly in Mathematica but not in Player Pro, while

DynamicModule[{grf, x}, 
 Panel[{Button["Export", Export["test.png", grf]], 
   Slider[Dynamic[x], {1, 4}], 
   Dynamic[grf = Graphics[{Line[{{1, x}, {x, 1}, {3, 2}}]}]]}]]

exports properly in both?

$\endgroup$
2
$\begingroup$

I cannot tell you, why Mathematica can handle your first case properly, while the Player doesn't, but I can tell you why your first example is wrong. Writing something like

grf = Dynamic[Graphics[....

is a bad idea, because, although you don't see it, the Dynamic head is still there. You can observe this by changing your example slightly

DynamicModule[{grf, x}, 
 Panel[{Button["Export", Print[InputForm[grf]]], 
   Slider[Dynamic[x], {1, 4}], 
   grf = Dynamic[Graphics[{Line[{{1, x}, {x, 1}, {3, 2}}]}]]}]]

When you now hit the button, then you see that you don't have a Graphics, you have a Graphics wraped in Dynamic. I guess the player cannot handle this.

You second example is correct, because you dynamicly set grf by wrapping the complete expression. Use the same print and you see that Export will get a correct Graphics object.

$\endgroup$
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.