Using the custom SimpleGraph class from flashandmath.com

An alternate title for this tutorial could be, "How to make a functional grapher in 30 lines of code." With the custom SimpleGraph class available from flashandmath.com, creating a graph of an expression in one variable is a snap. Although the example in this tutorial shows a graph in rectangular coordinates, the SimpleGraph class supports graphs in parametric and polar coordinates as well. For additional examples of using the SimpleGraph class as well as the fundamentals of graphing that make the class work, see our new book, Flash and Math Applets: Learn by Example, linked on the bottom right side of this page.

In the applet shown below, the user enters minimum and maximum values for x and y and an expression in the variable x. Hitting the "Enter" key then graphs the expression. The values for x and y can include expressions like "pi" or "sqrt(2)".

Download

Download both fla files for this tutorial, along with the folder of class files and their documentation, in the following compressed folder.

Notes

The examples here require the following import statement so the SimpleGraph class is available to our code. The folder flashandmath included in the compressed file above must be in the same directory as the fla file for the applications you develop using this custom class.

import flashandmath.as3.tools.SimpleGraph;

Back to Basic Tutorials              Back to Flash and Math Home

We welcome your comments, suggestions, and contributions. Click the Contact Us link below and email one of us.

Adobe®, Flash®, ActionScript®, Flex® are registered trademarks of Adobe Systems Incorporated.