The custom math class included with this tutorial is designed to handle the arithmetic of fractions. While fractional input is something that is easy to handle using our general MathParser class, when exact calculations and output for fractions is needed, we need a different tool. The applet shown below, and explained on the third page of this tutorial, shows the basic idea. The user can enter an answer only as an integer or as a fraction, and the program checks whether the user's answer is equal to the correct fraction.
This tutorial is in the "Bridging the Gap" area of the site because in our custom Fraction class we address two constructs for functions that are particularly important for creating flexible classes. These ideas are "untyped" input parameters and the use of ... rest (as it is called in the Adobe documentation) to allow for indeterminate number of input parameters.
In addition to the example shown above, we include a similar example in which a student must solve two equations in two unknows and another that gives a standard precalculus problem (finding the vertex of a parabola) that commonly has fractional answers.
Download all three fla files as well as the Fraction.as class file in the following compressed folder.
On the next page, we present the custom AS3 Fraction class.