Eureka! My first red5 application!
Boo-ya! Finally got this working! My "Hello world" red5 app is attached...It's nothing fancy (adds two numbers together and spits it out in the eclipse debug console), but I couldn't find a good template to work off of that used red5 v.8 and Flex w/ AS3, so here it is.
You'll need Adobe Flex Builder set up in Eclipse to run this.
Installation:
1) Unzip myapp.tar_.gz and place myapp/ in ~/projects/red5/dist/webapps
2) Unzip red5test.tar_.gz and place into your eclipse workspace.
3) make sure to recompile red5 with "ant server"...Read through the log and make sure you don't see any errors.
4) Import the red5test folder into eclipse and debug it as a flex application. If all goes well, you should see that it connected successfully and added 33 + 2 together.
Here are the two important chunks of code (the rest is mostly configuration)
Application.java - the red5 main class
package org.red5.server.webapp.myapp;
import org.red5.server.adapter.ApplicationAdapter;
public class Application extends ApplicationAdapter
{
public double addSomething(double a, double b)
{
log.info("adding " + a + " + " + b);
return a + b;
}
}red5test.mxml - The flex file with an inline AS3 script to launch a netconnection and connect to red5
NOTE- feel free to weed out the unused imports, I am too lazy.
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="connect()">
<mx:Script>
<![CDATA[
import flash.display.MovieClip;
import flash.media.Camera;
import flash.media.Microphone;
import flash.media.Video;
import flash.net.NetConnection;
import flash.net.NetStream;
import flash.events.NetStatusEvent;
import flash.events.AsyncErrorEvent;
import flash.display.SimpleButton;
import flash.text.*;
import flash.system.SecurityDomain;
import flash.system.Security;
import flash.net.Responder;
private var nc:NetConnection;
private var responder:Responder;
public function connect():void
{
nc = new NetConnection();
nc.connect("rtmp://localhost/myapp");
nc.addEventListener(NetStatusEvent.NET_STATUS,net_status_handler);
responder = new Responder(setValue, null);
}
private function net_status_handler(event:NetStatusEvent):void
{
var code:String = event.info.code;
trace(code);
if(code== "NetConnection.Connect.Success")
{
trace("Success");
nc.call("addSomething", responder, 2, 33);
}
else
{
trace("Fault");
trace(code);
}
}
private function setValue(obj:Object):void
{
trace(obj.toString());
}
]]>
</mx:Script>
</mx:Application>| Attachment | Size |
|---|---|
| myapp.tar_.gz | 6.15 KB |
| red5test.tar_.gz | 252.65 KB |