Difference between revisions of "FlashPointAndGraph"

From WeBWorK_wiki
Jump to navigation Jump to search
(New page: <h2>Flash applet example: Graph and Point</h2> <!-- Header for these sections -- no modification needed --> <p style="background-color:#eeeeee;border:black solid 1px;padding:3px;"> <e...)
 
Line 93: Line 93:
 
<code>getState</code> and <code>setState</code> are used to remember the applets state between invocations of the question. Students will find their questions in the same state they left them when they last worked on the question. The state changes as the student manipulate the applet.
 
<code>getState</code> and <code>setState</code> are used to remember the applets state between invocations of the question. Students will find their questions in the same state they left them when they last worked on the question. The state changes as the student manipulate the applet.
 
</p>
 
</p>
<p> <code>getConfig</code> is one way that the applet can do one-time configuration when it is first initialized in a problem. This allows one applet to be used for several different questions. The command loads the <code>&lt;xml&gt;</code> data in the <code>configuration</code> defined below, in this case determining the function used in the question.
+
<p> <code>getConfig</code> is one way that the applet can do one-time configuration when it is first initialized in a problem. This allows one applet to be used for several different questions. The command loads the <code>&lt;xml&gt;</code> data in the <code>configuration</code> variable defined below, in this case determining the function used in the question.
 
</p>
 
</p>
 
<p><code>answerBox</code> is the name of the default text box for returning the answer from the applet. It is revealed when debugMode is 1 or 2 and hidden otherwise. </p>
 
<p><code>answerBox</code> is the name of the default text box for returning the answer from the applet. It is revealed when debugMode is 1 or 2 and hidden otherwise. </p>
 
<p>
 
<p>
 
<code>debugMode</code>, when equal to 1, reveals two text boxes -- one containing the state of the applet and the other the answer that the flash applet submits to the WeBWorK question, along with some buttons for controlling the information in these boxes. When <code> debugMode</code>==2, additional alert messages are generated which detail progress through the initialization steps. This can be very helpful for debugging communication difficulties between the applet and the WeBWorK question
 
<code>debugMode</code>, when equal to 1, reveals two text boxes -- one containing the state of the applet and the other the answer that the flash applet submits to the WeBWorK question, along with some buttons for controlling the information in these boxes. When <code> debugMode</code>==2, additional alert messages are generated which detail progress through the initialization steps. This can be very helpful for debugging communication difficulties between the applet and the WeBWorK question
<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.
+
<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>
 
</td>
 
</td>

Revision as of 20:48, 30 April 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.

Problem Techniques Index

PG problem file Explanation
  loadMacros("AppletObjects.pl",
             "answerHints.pl"
  );

In the initialization section, we need to include the macros file AppletObjects.pl and, to provide good feedback, answerHints.pl.

  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 Point, and setup and define the mathematics information. (We will be asking the student to drag the dot to the inflection point of the function.

  ###################################
  # 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 PointGraph. The findAppletCodebase("PointGraph.swf") directs that the file PointGraph.swf be located in the (1) the course's html directory (reachable from the file manager) (2) the webwork sites's htdocs/applets directory -- maintained by the site administrator. The locations searched for the file PointGraph.swf is defined in the site's global.conf file.

The aliases match names used by WeBWorK javaScript code to the subroutine and function names used by the FlashApplet. If the applet has been designed specifically to work with WeBWorK questions you will not need to change these, but if you are adapting an applet designed for other uses to a WeBWorK question then you can use these aliases to avoid making modifications to the applet.

getState and setState are used to remember the applets state between invocations of the question. Students will find their questions in the same state they left them when they last worked on the question. The state changes as the student manipulate the applet.

getConfig is one way that the applet can do one-time configuration when it is first initialized in a problem. This allows one applet to be used for several different questions. The command loads the <xml> data in the configuration variable defined below, in this case determining the function used in the question.

answerBox is the name of the default text box for returning the answer from the applet. It is revealed when debugMode is 1 or 2 and hidden otherwise.

debugMode, when equal to 1, reveals two text boxes -- one containing the state of the applet and the other the answer that the flash applet submits to the WeBWorK question, along with some buttons for controlling the information in these boxes. When debugMode==2, additional alert messages are generated which detail progress through the initialization steps. This can be very helpful for debugging communication difficulties between the applet and the WeBWorK question

submitActionScript 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.)

  BEGIN_TEXT
  ...... question text ......
  END_TEXT

The problem text section of the file is as we'd expect.

  ANS( $expr->cmp() );

As is the answer.

Problem Techniques Index