Online Book Reader

Home Category

Developing Android Applications with Adobe AIR [94]

By Root 2516 0

function onStatus(event:NetStatusEvent):void {

switch(event.info.code) {

case "NetGroup.SendTo.Notify" :

trace(event.info.fromLocal);

// if true, recipient is the intended destination

var message:Object = event.info.message;

(if message.type == "direction") {

trace(message.value); // south

}

break;

}

}

Relay


A simple message relay service was introduced in January 2011. It is not intended for ongoing communication, but rather for a few introductory messages, and is a feature for the Cirrus service only. It requires that the sender knows the PeerID of the recipient.

The sender requests a relay:

connection.call("relay", null, "RECIPIENT_ID", "hello");

The recipient receives and responds to the relay:

connection.client = this;

function onRelay(senderID:String, message):void {

trace(senderID); // ID of the sender

trace(message); // "hello"

}

Treasure Hunt


This treasure hunt game illustrates various aspects of this technology.

Referring to Figure 15-3, imagine the first user on the left walking outdoors looking for a treasure without knowing where it is. She streams a live video as she walks to indicate her progress. The second user from the left knows where the treasure is but is off-site. She guides the first user by pressing keys, representing the cardinal points, to send directions. Other peers (in the two screens toward the right) can watch the live stream and chat among themselves.

Figure 15-3. The Treasure Hunt activity; the panels shown here are (left to right) for the hunter walking, for the guide, and for users viewing the video and chatting over text

Review the sample code provided in this chapter to build such an application. We covered a one-to-many streaming example. We discussed chat in an earlier example. And we just went over sending direct messages.

As a final exercise, you can put all the pieces together to build a treasure hunt application. Good luck, and please post your results.

Other Multiuser Services


If you want to expand your application beyond what this service offers, several other options are available to set up communication between parties remotely, such the Adobe Media Server, Electrotank’s ElectroServer, and gotoAndPlay()’s SmartFox. All of them require server setup and some financing.

ElectroServer was developed for multiplayer games and tools to build a multiplayer lobby system. One installation scales up to tens of thousands of connected game players with message rates of more than 100,000 messages per second. You can try a free 25-user license (see http://www.electrotank.com/). Server-side code requires Java or ActionScript 1. It supports AIR and Android.

SmartFox is a platform for developing massive multiuser games and was designed with simplicity in mind. It is fast and reliable and can handle tens of thousands of concurrent clients with low CPU and memory usage. It is well documented. You can try a full version with a free 100-user license (see http://www.smartfoxserver.com/). Server-side code requires Java. It supports AIR and Android.

Arduino and Physical Computing

Arduino is an open source electronics platform comprising easy-to-use hardware and software. The microcontroller can receive input from a range of sensors and can send signals to control other devices. It is an environment for bridging computers and the physical world, also called physical computing.

Purchase an Arduino board and a USB cable, and download the software and drivers. Note that you can build your own board and circuitry, but Arduino offers the ease of use of already custom-made boards, especially if this is a new area for you.

Arduino can communicate with ActionScript and AIR via TinkerProxy or Serproxy, which are local proxies between the serial port and AIR via a socket server.

Read Mike Chambers’s blog on how to get started, at http://www.mikechambers.com/blog/2010/08/04/getting-started-with-flash-and-arduino/.

Mike also developed a speed detector project for gear cars. It uses AIR 2.5 for Android. Two photo resistors are connected to the board that

Return Main Page Previous Page Next Page

®Online Book Reader