Actionscript 3.0 Tutorial


Introduction

All Apache Thrift tutorials require that you have:

  1. Built and installed the Apache Thrift Compiler and Libraries, see Building from source for more details.
  2. Generated the tutorial.thrift and shared.thrift files as discussed here.

    thrift -r --gen as3 tutorial.thrift
    
  3. Followed all prerequisites listed below.

Prerequisites

Client

To initialize client you can use code similar to:

    private function initConnection():void {
      mTransport = new TSocket("127.0.0.1", 9090); // we connect to server
      mTransport.open();
      // initialize protocol:
      var protocol:TProtocol = new TBinaryProtocol(mTransport, false, false);
      mCalculatorClient = new CalculatorImpl(protocol); // finally, we create calculator client instance
    }

Server

The example client above can be tested against a java tutorial server.

Additional Information

You might find server failing due to out of memory exception. This might happen because of flash crossdomain policy. See next passage on how to fix this.

Flash crossdomain policy

Flash does not allow movies to connect to arbitrary servers. This is done for security reasons. To override this restriction, however, servers' owners can create special file - crossdomain xml file, which lists the rules according to which some flash movies can connect to the server.

Details about this behavior are listed in Setting up a socket policy file server. Also, you can find a simple python/perl server script to serve this file there. For same host, you can serve crossdomain.xml from any port. So, you can start your RPC servers on ports 9090 and 9091, and serve polisy file from port 9092. To tell flash about this, you can use code from tutorial file:

    private function initSecurity():void {
      Security.loadPolicyFile("xmlsocket://127.0.0.1:9092");
    }

Example of crossdomain file, to allow connect to ports 9090 and 9091 from any server:


<?xml version="1.0"?>
<!DOCTYPE cross-domain-policy SYSTEM "/xml/dtds/cross-domain-policy.dtd">
<!-- Policy file -->
<cross-domain-policy>
  <allow-access-from domain="*" to-ports="9090,9091" />
</cross-domain-policy>