The AdditionExample Applet: Difference between revisions
Jump to navigation
Jump to search
Line 10: | Line 10: | ||
#Name the text fields, respectively, <code>txtFirstNumber</code>, <code>txtSecondNumber</code> and <code>txtResult</code>. | #Name the text fields, respectively, <code>txtFirstNumber</code>, <code>txtSecondNumber</code> and <code>txtResult</code>. | ||
#Create a new ActionScript 3.0 class file and add the following code: | #Create a new ActionScript 3.0 class file and add the following code: | ||
<nowiki> | <nowiki>package { | ||
package { | |||
import flash.display.MovieClip; | import flash.display.MovieClip; | ||
Line 38: | Line 37: | ||
} | } | ||
} | } | ||
} | }</nowiki> | ||
save it as '''AdditionExample.as''. | save it as '''AdditionExample.as''. |
Revision as of 18:46, 29 June 2011
Introduction
In this example, it is shown how to set up a simple applet for use in a WeBWork problem. The complete code for the applet, as well as the corresponding PG file, can be downloaded from (add download site). The applet, shown below, asks for the sum of two integers. Notice that there are no buttons for checking the answer in the applet, since this will be handled by WeBWork.
Initial Setup
The initial code for the applet can be downloaded from (add download site), or it can be created by the following steps.
- Create a new applet in Flash and draw the controls as shown in the picture above. The first two text fields are of type Dynamic Text, and the rightmost one is of type Input Text
- Name the text fields, respectively,
txtFirstNumber
,txtSecondNumber
andtxtResult
. - Create a new ActionScript 3.0 class file and add the following code:
package { import flash.display.MovieClip; /* Class: AdditionExample A simple example of an applet for a WeBWork problem. This is the starting point for the tutorial on how to set up the interface between a Flash applet and WeBWork */ public class AdditionExample extends MovieClip { /* Constructor: AdditionExample Constructs an object of class <AdditionExampleStart>. */ public function AdditionExample() { //The following statments are used just for testing the applet //offline, and should be commented out in the online version. //When used in a WeBWork context, these are set by setConfig() txtFirstNumber.text = "9"; txtSecondNumber.text = "7"; } } }
save it as 'AdditionExample.as.