PDA

View Full Version : [AS3] ColorPicker vs. Red5


stilledansker
12-09-2010, 05:07 PM
dear AS board!
I'm working on a research project involving color-communication in a closed environment. I've been trying to develop an application for communicating between 2 computers, based on the red5 server possibilities.

I'm very novice in AS... :) - so there really is some basic stuff that i'm missing in this project to connect the pieces - there fore i'm really hoping for someone to help point me in the right direction.

I'm building upon two components; a colorpicker tutorial, and the basic chat component in red5.

My goal is to have 2 browser .swf's running where the participants can pick a color, output the #hexcode to change the background of a 2 sharedObject's in the browser. (so they are not interfering with the same object, but using each their picker and receiving each own color to object)

Colorpicker code:
package
{
import flash.display.Sprite;
import flash.display.BitmapData;
import flash.geom.ColorTransform;
import flash.events.MouseEvent;

public class Main extends Sprite
{
var bitmapData:BitmapData = new BitmapData(300,300);
var colorTransform:ColorTransform = new ColorTransform();
var hexColor:*;

public function Main():void
{
bitmapData.draw(colorPicker.spectrum);
colorPicker.spectrum.addEventListener(MouseEvent.M OUSE_MOVE, updateColorPicker);
colorPicker.spectrum.addEventListener(MouseEvent.M OUSE_UP, setValue);
}

private function updateColorPicker(e:MouseEvent):void
{
hexColor = "0x" + bitmapData.getPixel(colorPicker.spectrum.mouseX,co lorPicker.spectrum.mouseY).toString(16);
colorTransform.color = hexColor;

colorPicker.color.transform.colorTransform = colorTransform;
colorPicker.colorHex.text = "#" + bitmapData.getPixel(colorPicker.spectrum.mouseX,co lorPicker.spectrum.mouseY).toString(16).toUpperCas e();
}

private function setValue(e:MouseEvent):void
{
txt.textColor = hexColor;
colorPicker.selectedColor.transform.colorTransform = colorTransform;
colorPicker.sColor.text = colorPicker.colorHex.text;
colorPicker.selectedColor.alpha = 100;
}

}
}

The colorpicker works and outputs as it should. The issue is basically around mounting the hexcode string through a button to change the background of the remote object using the red5 .fla.

import mx.utils.Delegate;


var nc:NetConnection = new NetConnection();

//remotehost

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

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

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

so.connect(nc);

//need to do a hexcode import to the messagehandler, to change the color of an object

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

Key.addListener(this);

function sendColor():Void
{
so.data.ColorMessage = message.text;

message.text = "";
}

}

Maybe this should really be posted in the newbie section :)
could any of you show me in the right direction?

Best regards