Posted by: Robin Leboe | August 23, 2008

Flashserver install: OS X (Tiger)

After downloading the latest version of Flashserver and expanding the archive I placed the flashserver.mxo object in the max-startup folder of the Applications/MaxMSP4.6 directory. This is not per the manual, which directs you to place the file in the Application Support folder. I also placed the flashserver.help file in the max-help folder as directed. So far so good!

After loading up a new Max patch I created an Object Box and scrolled through the list to find the Flashserver object type and set the port parameter to 5150 (arbitrary – even crazy! – but above 1024 to avoid collisions with OS ports). I also specified 1 connection out of a possible 256.

Uber basic Max/MSP 4.6 patch for Flash communication

Uber basic Max/MSP 4.6 patch for Flash communication

On the Flash side, I specified the FlashserverConnect class as the Document class and made sure that the port parameter specified in the class was also set to 5150. Here’s the class:

package {

import flash.display.Sprite;
import flash.events.Event;
import flash.events.DataEvent;
import flash.events.IOErrorEvent;
import flash.events.ProgressEvent;
import flash.net.XMLSocket;
import flash.events.IEventDispatcher;

// FlashserverConnect must extend Sprite to serve as Document class in CS3
public class FlashserverConnect extends Sprite {

private var host:String = “localhost”;
private var port:uint = 5150; // LAPD code for crazy person (!?)
private var socket:XMLSocket; // Create socket
private var val:String = “Hello from Flash”; // initial value for testing
private var header:String = “val”;
private var maxData:* = header + ” “+ val + “;”

public function FlashserverConnect() {

socket = new XMLSocket();
configureListeners(socket);
socket.connect(host, port);
send(maxData);
}

public function send(data:Object):void {

trace(“sending “+data);
socket.send(data);
}

private function configureListeners(dispatcher:IEventDispatcher):void {

dispatcher.addEventListener(Event.CLOSE, closeHandler, false, 0, true);
dispatcher.addEventListener(Event.CONNECT, connectHandler, false, 0, true);
dispatcher.addEventListener(DataEvent.DATA, dataHandler, false, 0, true);
dispatcher.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler, false, 0, true);
dispatcher.addEventListener(ProgressEvent.PROGRESS, progressHandler, false, 0, true);
}

private function closeHandler(event:Event):void {

trace(event.type + “Handler: Closed”);
}

private function connectHandler(event:Event):void {

trace(event.type + “Handler: Connected”);
}

private function dataHandler(event:DataEvent):void {

trace(“data received” + event);
}

private function ioErrorHandler(event:IOErrorEvent):void {

trace(event.type + “Handler  ” + event.text);
}

private function progressHandler(event:ProgressEvent):void {

trace(“progress…”);
}

}

}

The next step was to test the Flash movie and view the results in Max/MXP’s output panel…

Success! Now we can get down with some serious Max Flash fun.


Leave a response

Your response:

Categories