FlashPointAndGraph: Difference between revisions
No edit summary |
No edit summary |
||
| Line 104: | Line 104: | ||
<p><code>submitActionScript</code> is a short javaScript command which is one way of customizing the behavior of the applet when the submit button is pressed. (It should not contain line breaks to satisfy javaScript requirements.) | <p><code>submitActionScript</code> is a short javaScript command which is one way of customizing the behavior of the applet when the submit button is pressed. (It should not contain line breaks to satisfy javaScript requirements.) | ||
</p> | </p> | ||
<p>[[FlashApplets | FlashApplets]] describes this interface from the flash applets point of view. | <p>''[[FlashApplets | FlashApplets]]'' describes this interface from the flash applets point of view. | ||
</p> | </p> | ||
</td> | </td> | ||
Revision as of 01:52, 1 May 2009
Flash applet example: Graph and Point
This code snippet shows the essential PG code to check student answers that are equations. Note that these are insertions, not a complete PG file. This code will have to be incorporated into the problem file on which you are working.
| PG problem file | Explanation |
|---|---|
loadMacros("AppletObjects.pl",
"answerHints.pl"
);
|
In the initialization section, we need to include the macros file |
Context("Point");
$a = Real( random(-4,4,0.5) );
$b = Real( random(-3,3,1) );
$function = Formula("(x - $a)^3 + ($b/$a) * x")->reduce;
$x0 = $a;
$y0= $function->eval(x=>$x0);
$answer_point = Compute("($x0, $y0)");
|
In the problem set-up section of the file, we specify that the Context should be |
###################################
# Create link to applet
###################################
$appletName = "PointGraph";
$applet = FlashApplet(
codebase => findAppletCodebase("$appletName.swf"),
appletName => $appletName,
appletId => $appletName,
setStateAlias => 'setXML',
getStateAlias => 'getXML',
setConfigAlias => 'setConfig',
answerBoxAlias => 'answerBox',
debugMode => 0,
submitActionScript =>
qq{getQE("answerBox").value=getApplet("$appletName").getAnswer() },
);
|
This snippet defines the applet
The
The
FlashApplets describes this interface from the flash applets point of view. |
###################################
# Configure applet
###################################
#data to set up the equation
$applet->configuration(qq{<XML expr='$function' />});
# initial points
$applet->initialState(qq{<XML> <pt xval='0' yval='0'/></XML>});
###################################
#insert applet into body
###################################
TEXT( MODES(TeX=>'object code', HTML=>$applet->insertAll(
debug=>0,
includeAnswerBox=>1,
reinitialize_button=>$permissionLevel>=10,
)));
|
Now we configure the applet. The contents of The |
BEGIN_TEXT $PAR Drag the point to the inflection point of the given curve and press the submit button. END_TEXT |
The problem text section of the file is as we'd expect. |
NAMED_ANS('answerBox'=>$answer_point
->with(tolType=>"absolute",tolerance=>.05)
->cmp
->withPostFilter(AnswerHints(
sub {
my ($correct,$student,$ans) = @_;
return Vector($correct-$student)->norm<.2 ;
} => ["You're close. You need to position
the dot more precisely.", replaceMessage=>1]
)));
|
The answer checker grabs the answer from the default |