Accessibility
 
Home > Products > Flash > Support > Building Applications
Flash Icon Macromedia Flash Support Center - Building Applications
Sending the TRANSACTION element

The user interface of the Flash movie allows the user to enter a series of buy/sell trades. After these trades are entered, you want to transmit these trades to the server using the TRANSACTION element. To do this, the user interface scripts must first convert the data into an easy-to-manipulate form. You must create an Array object called trades that consists of one or more Trade objects. The Trade object is defined by the following construction function:

function Trade(action, type, symbol, qty, price){
  this.action = action;
  this.type = type;
  this.symbol = symbol;
  this.qty = qty;
  this.price = price;
}

The following is an example of populating the trades array:

trades = new Array();
trades[0] = new Trade("BUY", "MARKET", "RICH", 50);
trades[1] = new Trade("SELL", "LIMIT", "POOR", 100, 50.375);

Note that the price argument may be omitted, in which case its value is set to undefined .

When the user presses the Submit Your Order button to execute the trades, the following button actions are executed:

on (release){
  // Construct a XML document with a TRANSACTION element
  transactionXML = new XML();
  transactionElement = transactionXML.createElement("TRANSACTION");
  transactionElement.attributes.session = sessionID;
  transactionXML.appendChild(transactionElement);

  // Copy the "trades" array into the TRANSACTION element
  for (var i=0; i<trades.length; i++) {
    var tradeElement = transactionXML.createElement("TRADE");
    tradeElement.attributes.action = trades[i].action;
    tradeElement.attributes.type = trades[i].type;
    tradeElement.attributes.symbol = trades[i].symbol;
    tradeElement.attributes.qty = trades[i].qty;
    if (typeof(trades[i].price) != "undefined")
      tradeElement.attributes.price = trades[i].price;
    }
    transactionElement.appendChild(tradeElement);
  }

  // B. Construct a XML object to hold the server's reply
  transactionReplyXML = new XML();
  transactionReplyXML.onLoad = onTransactionReply;

  // Send the TRANSACTION element to the server,
  // place the reply in transactionReplyXML
  transactionXML.sendAndLoad("https://www.imexstocks.com/main.cgi",
                              transactionReplyXML);
}
As an exercise, you might try implementing the onTransactionReply() function.

To Table of Contents Back to Previous document