Posted by Omi on Mon 28 Jul 03:08 (modification of post by Omi view diff)
report abuse | download | new post
- //////////////////////////////////////////////////////////////////////
- //
- // Add numbers sample application (AS3).
- //
- // 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 com.mangosix.SWX;
- var swx:SWX;
- function init()
- {
- // Set up the display
- progressIndicator.visible = false;
- this.n1.restrict = "0-9.\\-";
- this.n2.restrict = "0-9.\\-";
- this.addButton.label = "Add";
- // Listen for the click event on the add button
- this.addButton.addEventListener("click", 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(e:Event)
- {
- // Set call details.
- var callDetails:Object =
- {
- serviceClass: "Simple",
- method: "addNumbers",
- args: [this.n1.text, this.n2.text],
- result: [this, resultHandler],
- timeout: [this, timeoutHandler]
- }
- // 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;
- this.addButton.enabled = !state;
- this.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.