[ICS] Ivory City Systems


mod_perlservice


COURTESY OF
IVORY CITY SYSTEMS
For custom business solutions with the mod_perlservice web services platform, visit: www.ivorycity.com/services.html

mod_perlservice developed by:
Michael W. Collins
Documentation by: Michael W. Collins
Questions/Comments/Bugs:
michaelcollins@ivorycity.com


DOWNLOAD
PerlService-1.0.4.as

Sorry, the full flash client documentation hasn't been published yet. Please refer to the example below to get you started.

Okay, lets create that stock portfolio example we talked about earlier. We won't implement realtime quotes, but instead we'll create a static database of some common stock names and historical prices. Our application will support stock information for General Electric (GE), Red Hat (RHAT), Coca Cola (KO), and Caterpillar (CAT).

The application will be called stockmarket and we should place all our perl files in the stockmarket application directory (/home/services/stockmarket). The first file will be "quotes.pm" and it reads as follows:


#include "PerlService-0.0.2.as"

// Create a global PerlService object
// Tell the PerlService object about the remote code we want to use:
// arg1) host: www.ivorycity.com
// arg2) application: stockmarket
// arg3) file: quotes.pm
// arg4) package: quotes

_global.ps = new PerlService("www.ivorycity.com","stockmarket","quotes.pm","quotes");

// First declare three callback  functions to handle return values
 
function
onStockPrice(val)
{
  output.text = "StockPrice: " + symbolInput.text + " " + val + "\n" + output.text;
}

function
onAllStockInfo(val)
{
  output.text = "Stock Info: " + allInfoInput.text + "\n" +
        "\tPrice: " + val.Price + "\n" +
        "\tEarnings Per Share: " + val.EarningsPerShare + "\n" +
        + output.text;
}

function
onLookupSymbol(val)
{
  output.text = "Lookup Result: " + symbolInput.text + " " + val + "\n" + output.text;
}

// Register callback handlers for managing the return values from the remote methods
// ie. onStockPrice receives the return value from remote method getStockPrice

ps.registerReplyHandler( "getStockPrice",  onStockPrice );
ps.registerReplyHandler( "getAllStockInfo", onAllStockInfo );
ps.registerReplyHandler( "lookupSymbol",  onLookupSymbol );



Now for the code that makes things happen! The following code is attached to three separate buttons. When clicked, the buttons call the remote perl methods using the global PerlService object. Flash Action Script is an event driven system, so click event handlers will call the remote code and return event handlers will do something with those values.



Button 1 Code

When Button 1 is clicked, call the remote method "getStockPrice" and pass the text in the first input box as an argument.

on (release)
{
  ps.getStockPrice(box1.text);
}

Button 2 Code

When Button 2 is clicked, call the remote method "getAllStockInfo" and pass the text in the second input box as an argument.

on (release)
{
  ps.getAllStockInfo(box2.text);
}

Button 3 Code

When Button 3 is clicked, call the remote method "lookupSymbol" and pass the text in the third input box as an argument.

on (release)
{
  ps.lookupSymbol(box3.text);
}

Okay, that's our Flash example! Here is the finished product below.




Questions-Comments-Support
  michaelcollins@ivorycity.com
 
  Copyright © Ivory City Systems 2004.
  You have permission to copy and redistribute this document
so long as it retains this original copyright and trademark information.

 
  The Seahorse Emblem is a Trademark of Ivory City Systems.