|
Step 3: Create the Flash Interface
Once you get the listener and application out of the way, you can move on to the Flash front-end. If you need help understanding Flash authoring, visit Macromedia's Flash support center.
To begin, set up an interface in Flash for a simple calculator. The interface behaves like a standard digital calculatordisplaying figures when the user enters them on a keypad and showing calculated values when the user pushes an operator button or the equals button. To simulate a calculator, the Flash movie maintains a set of global variables containing numeric values and the most recent arithmetic operator, updating these variables when the user clicks the buttons on the interface. Three root-level variables hold these data:
- _root.calcValue stores the numeric value for the calculator display
- _root.operator stores the selected arithmetic operation
- _root.lastValue stores the value of root.calcValue when the user pushes an operator button.
The demo uses some graphics and has space to display the text of the SOAP messages, but you can use a simpler interface if you wish. Create symbols with button behaviors, one for each number, each operator, the decimal point, and the equals sign. Also, create a text box for the calculator display. In Flash, a Dynamic Text field binds the value of a variable to a text box, so the text display and the variable value update when either one changes. To bind the text box to the variable, choose Dynamic Text from the drop-down options list on the text options panel, and set the bound variable to _root.calcValue.
Next, create corresponding labels inside each of the buttons and assign an action to each that updates the tracking variable _root.calcValue. On each operator button, add an action to set the variable _root.operator to the requested calculation operator. Make sure that the string value of the operator corresponds to the value expected by the SOAPCalc component on the server. In the same action, add code to save the current calculator figure in a variable called _root.lastValue so you can recall it to perform the requested operation when the user presses the equals key. Also, include any necessary script for updating the display. At a minimum, the operator buttons should contain these actions:
on (release) {
// choose "Add", "Subtract", Multiply", or "Divide"
_root.operator = "Add";
_root.lastValue = _root.calcValue;
...
}
Next, add an action to the equals sign button that calls a function to send the SOAP message and do the calculation:
on (release) {
_root.calculate(_root.operator, _root.lastValue, _root.calcValue);
}
In a new layer at the root level of the movie, create an action that houses all the functions for the application. In this action block, add a calculate() function to broker the SOAP requests and responses to and from the server.
In its most basic form, calculate() takes parameters for an operator and two operands and sends them to the server.
function calculate(operator, a, b) {
...
}
|
 |
TALK
BACK |
|
Did you know that Flash 5 was capable of making SOAP calls to server-side code? Using Flash 5's XML capabilities, you can build highly interactive thin-client applications? Let us know what you think of the techniques in this article? Join the discussions at web.server.general and let us know.
|
|
|
|
|
|
|