Posted by Omi on Mon 28 Jul 03:07
report abuse | View followups from Omi | download | new post
- //////////////////////////////////////////////////////////////////////
- //
- // Add numbers sample application.
- //
- // Copyright (c) 2007 Aral Balkan.
- // All SWX sample applications are released under the open source
- // MIT License (http://www.opensource.org/licenses/mit-license.php).
- //
- // This version uses the SWX ActionScript Library.
- //
- // The SWX ActionScript Library gives you a completely abstract and
- // high-level way of working with SWX RPC. It is the recommended way
- // to use SWX RPC in your applications unless you need the
- // flexibility that the native methods give you (which you may do,
- // for example, if you want to create your own high-level library.)
- //
- //////////////////////////////////////////////////////////////////////
- import org.swxformat.*;
- import mx.utils.Delegate;
- var swx:SWX;
- function init()
- {
- // Set up the display
- progressIndicator._visible = false;
- n1.restrict = "0-9.\\-";
- n2.restrict = "0-9.\\-";
- // Listen for the click event on the add button
- addButton.addEventListener("click", Delegate.create(this, addButtonClickHandler));
- // Create a new SWX object
- swx = new SWX();
- swx.gateway = "http://swxformat.org/php/swx.php";
- swx.encoding = "GET";
- // By default, this example uses the public SWX gateway on swxformat.org.
- // To use the local gateway instead, uncomment the following line (Unless
- // you're using the SWX MAMP Bundle, you will most likely have to alter
- // the URL below to point to your local installation of SWX PHP.)
- //
- // swx.gateway = "http://localhost:8888/php/swx.php";
- }
- init();
- // Load the movie
- function addButtonClickHandler()
- {
- // Set call details.
- var callDetails:Object =
- {
- serviceClass: "Simple",
- method: "addNumbers",
- args: [n1.text, n2.text],
- result: [this, resultHandler],
- timeout: [this, timeoutHandler],
- debug: true
- }
- // Carry out SWX call.
- swx.call(callDetails);
- isLoading(true);
- }
- function resultHandler(event:Object)
- {
- // Load is complete.
- isLoading(false);
- // Display the result.
- sum.text = event.result;
- }
- function timeoutHandler(event:Object)
- {
- // Call timed out.
- isLoading(false);
- status.text = "The call timed out. Please try again.";
- }
- function isLoading(state:Boolean)
- {
- status.text = state ? "Calling server-side service method to determine the result..." : "Tada! Wasn't that fun? Why not try two other numbers? Fun for all ages!";
- sum.text = "";
- progressIndicator._visible = state;
- addButton.enabled = !state;
- addButton._alpha = state ? 40:100;
- }
Submit a correction or amendment below (click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.