red5 chat revisited

April 28th, 2008 | 5 Comments | Posted in red5

As I continue to dig deeper into red5 I figured I would play around more with the chat demo…considering I need to build a complex communication tool for a client anyway….what better way to learn…

I’ve modified the code a little more by playing around with functionality, adding features like tool tips, user list, user icons, clearing the history, and a bit of skinning. I’m still trying to figure out how to add emo’s, sound, and user colour options.

I won’t go into all the code for the features I added, just the important chat stuff. I found a really great tool tip on google code you can grab it here, also a thank
you to Nick La of ndesign studios for the icons.

You can view the demo here.
bssChat2

We are still using the same connection method to red5

var nc:NetConnection = new NetConnection();
nc.connect("rtmp://localhost/oflaDemo");
var remote_so:SharedObject = SharedObject.getRemote("chat", nc.uri, false);
remote_so.connect(nc);

I have added a welcome screen that asks the user to enter a name. This way I can display a unique user list and easily add the user name to the output display. We create a var called username and datatype it as a string. We will build an array out of this later. The login window is inside an mc called login with the name field and submit button. When the submit buttton is clicked we will pass the name var to the user array and display it in the userlist. We will also add an icon to the name in the display list only.

var username:String;
Login.Name.setFocus();

function login():Void{
	ChatInput.setFocus();
	username = Login.Name.text;
	if (username == ""){username = "anonymous";}
	if (remote_so.data.users == undefined){
		remote_so.data.users = username;
	}else{
		remote_so.data.users += "," + username;
	}
	Login._visible = false;
}
Login.Submit.onRelease = login;

We will wrap all key events and messages into eventListers, it’s easier this way and it condenses the code.

keyListener = new Object();
keyListener.onKeyDown = function (){
if(Key.getAscii() == 13 && Login._visible == false){
sendMessage();
}else if(Key.getAscii() == 13){
login();
}
}

Key.addListener(keyListener);

Enter.onRelease = sendMessage;

function sendMessage(){
if (remote_so.data.chatText == undefined){
remote_so.data.chatText =  "" + username + ": " + ChatInput.text;
}else{

remote_so.data.chatText = "" + username + ": " + ChatInput.text;
}
ChatInput.text = "";
}

For the onSync function we call the list and pass the user names to an array and display them in the userlist. we will also pass the chatText to the output and set the scrollbar positions.

remote_so.onSync = function(list){
	if (remote_so.data.chatText != undefined){
		ChatOutput.text += remote_so.data.chatText;
		ChatOutput.vPosition = ChatOutput.maxVPosition;
	}
	var userArray:Array = remote_so.data.users.split(",");
	Userlist.dataProvider = userArray;
}

That’s all…not bad eh! For the skinning I just used some basic setStyles. I hope this helped.

red5 chat demo

April 27th, 2008 | 4 Comments | Posted in red5

Recently I have started playing around red5. I need to build a complex communication tool for one of my commercial projects. I can’t go into all the details, but this tool will allow people to chat with each other without having to log into or sign up for any service. It functions as a basic way for users to engage each other while they navigate the site. I won’t go into the installation of red5 right now. There are some really good tutorials here that can help walk you through it. It’s a little tricky, but once you get the hang of it’s a lot easier that you think.

In terms of testing red5 locally you can download and run a one click setup that will install a localhost, all the necessary com/org files, and a bunch of other goodies. You can find it here http://osflash.org/red5/070final.

This is one of my first attempts at building a simple red5 chat tool. I started with the sample chat source that comes bundled with red5 and I made a few adjustments to the code. In this sample I have not built any custom java files, I am using the SharedObject from the oflaDemo (which you can find in the src directory of your red5 install). There is a bit of a learning curve, red5 consist of more than just AS, as I have just recently discovered. I have started upgrading my java skills in order to start customizing and developing more powerful red5 apps. To all Flash developers out there, “don’t be afraid, it’s a lot easier than you think!”.

Ok, enough rambling, let’s get to the code…

[ JUST ADDED AN UPDATED VERSION WITH NEW FEATURES. VIEW HERE. ]

You can view the demo here.

bssChat

We will start by importing some basic flash utils and setting the initial variables to make a netConnection to our SharedObject and connect to our red5 server. We will the create a ShareObject to connect to. Then we will setup our onSync events to handle the messages we will be sending. Finally we will setup 2 basic EventListerners for click and key events.

import mx.utils.Delegate;// create basic netConnection object

var nc:NetConnection = new NetConnection();

// connect to the local Red5 server

nc.connect("rtmp://localhost");

// create StoredObject

var so:SharedObject = SharedObject.getRemote("chat", nc.uri, false);

// setup the onSync events.  We need to know when someone has added something to the chat

so.onSync = Delegate.create(this, newMessageHandler);

// connect to the SO using the netConnection reference

so.connect(nc);

// listen for the send button clicks

send.addEventListener("click", Delegate.create(this, sendMessage));

// add a listener for key events

Key.addListener(this);

Next we will set up our sendMessage function which will pass both the user name and message to the chat output display. We will also setup the key event as well so the user can press enter or click on the mouse.

function sendMessage():Void

{

 remote_so.data.chatMessage =  + userName.text +  - message.text;	message.text = "";

}

function onKeyUp():Void

{

 if(Key.getCode() == 13 && message.length > 0)

 {

 	sendMessage();

 }

}

The last function we will build is our newMessageHandler which essentially display all user output in a text area.

function newMessageHandler(evtObj:Object):Void

{	var newChat:String = remote_so.data.chatMessage;

if(newChat == null) return;

chatOutput.text += newChat + "\n";

chatOutput.vPosition = chatOutput.maxVPosition;

}

It’s that easy! Playing around with the code and some fun….please feel free to reply to this post with examples and variations on this project.

wii remote projects

April 26th, 2008 | 3 Comments | Posted in Open Source, c#

I thought I had seen it all until Nick Stupa, a former student of mine, posted a link on my facebook profile about interesting wii remote projects…

These are far more than interesting! This is some of the most promising and influential wii remote experiments I have seen to date…the possibilities are really endless!

Johnny Chung has some wicked experimental wii remote projects including finger tracking, digital whiteboard displays, and head tracking for Desktop VR Displays. The head tracking project really got my attention. Using the infrared camera in the Wii remote and a head mounted sensor bar, Johnny has developed a c# program that can accurately track the location of your head and render view dependent images on the screen. The end effect results in an interactive virtual 3D environment for the user. Not only can the user interact via a wii remote you the display also reacts to head and body movement as if it were a real window creating a realistic illusion of depth and space.

You have to see it for yourself…

 

All these programs are built using c# and Johhny has open sourced all the code and sample apps. I can’t wait to play around with the code and see what I can do to integrate some wii Flash apps as well.

For more information on Johnny’s projects http://www.cs.cmu.edu/~johnny/projects/wii/

Back from FITC…

April 25th, 2008 | 1 Comment | Posted in BackSpace Blabber, Industry, PHUG, Papervision

FITC was a huge success this year….

I’m happy to report that our booth, Seneca and PHUG, was the most popular booth on the floor…probably ’cause we where giving away FREE chocolate ;0

Attendees where very excited to see the student papervision3D work on display, it’s no swimming dolphin, but the students did a great job considering they had only 7 days to produce a full pv3 interface with collision and interactivity, GOOD JOB!!!
Kapachka

- kapachka interface developed by Students in the Digital Media Arts program at Seneca College, Alex Nasser, Miaomiao Kuang, Dan Coltri, Robbie Luziuz Vanin, Ricardo Jazmines, Amanda Labatia.

Another popular student project at FITC was pv3world.com, developed by Geoff Palin, Digital Media Arts student at Seneca College, this project drew attendees daily. Geoff Palin has also accepted a position at BackSpaceStudios as a lead developer, we are very happy to have him on board!
pv3world

Geoff Palin was also responsible for designing/developing the official Seneca@FITC blog http://www.phug.ca/fitc

Other highlights at the festival…

I had the opportunity to meet and geek out with the guy’s from papervision3D, paperworld3D, red5, Ribbit, and the one and only AS guru R Blank. I especially enjoyed discussing both PHUG and DMA student experimental pv3 work with Ralph Hauwert. I attended his Flash 2D and 3D effects presentation…all I can say is WOW! I also had the opportunity to sit down with Trevor Burton, the man behind paperworld3D. What an amazing individual, the man is an absolute genius! I’m hoping to contribute to the development of paperworld3D and eventually build some commercial apps with it…One of my favorite presentations was Ribbit. These guy’s have some of the coolest components I have seen in a long time. I am hoping to continue working with them on some PHUG and Seneca events as well as nominating some of my students for internships…I did not forget about R Blank…He gave an excellent presentation on AS3. BackSpaceStudios is happy to announce that we will be helping out with the re-build for the RMI site.

I will back post my blogs from the event under papervision, red5, and AS3.

Ribbit!

April 21st, 2008 | No Comments | Posted in AS3

Ribbit Logo

Ribbit is by far one of the coolest sets of CS3 components on the market!

Chuck Freedman, Director of Ribbit’s Development Platform, presented a new set of of UI components designed by Sir Keith Peters of Infrared5.

These new components will allow designers to have more control over Ribbit’s API. Up untill now Ribbit has only been available within the Flex developer community.

These new components will visually extend some of the code found in the Flex swc currently being distributed. Whats so cool about these UI components is the ability to easily build creative Ribbit applications in Flash with minimal code. Minimal code? you heard me right…I watched Chuck build a demo app during his presentation that was capable of dialing and loading a contact list with photos in mere seconds…no joke…and if that wasn’t enough he dived a bit into skinning!

What’s so unique about the skinning is they have built an easy click functionality that takes you to a skinning frame where you can make any changes you want on the fly…