from_ greenass hansune
As 3.0
// ------------------------------- volume sending part
var volLevel:Number ;
var snd:Sound = new Sound();
var channel:SoundChannel = new SoundChannel();
var req:URLRequest = new URLRequest("sound.mp3");
snd.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler);
snd.load(req);
channel = snd.play();
var conn:LocalConnection = new LocalConnection();
conn.addEventListener(StatusEvent.STATUS, onStatus);
function onStatus(event:StatusEvent):void {
switch (event.level) {
case "status" :
stat.text = "LocalConnection.send() succeeded";
break;
case "error" :
stat.text = "LocalConnection.send() failed";
break;
}
}
this.addEventListener(Event.ENTER_FRAME, sendData);
function ioErrorHandler(event:Event):void {
trace("ioErrorHandler: " + event);
}
function sendData(e:Event):void{
volLevel = Number(channel.leftPeak.toFixed(2))+ Number(channel.rightPeak.toFixed(2))*0.5;
conn.send("localhost:myConnection", "volHandler", 0,volLevel);
output.text = String(volLevel);
}
var output:TextField = new TextField();
addChild(output);
var stat:TextField = new TextField();
stat.y = 20;
stat.width = 200;
addChild(stat);
// ------------------------------- receive part
Security.allowDomain("localhost"); //important
var conn:LocalConnection = new LocalConnection();
conn.client = this;
try {
conn.connect("myConnection");
} catch (error:ArgumentError) {
trace("Can't connect...the connection name is already being used by another SWF");
}
///--- client function----
function unitHandler(num:Number):void {
output.text= String("unit : "+num);
}
function colorHandler(n:uint):void {
output.text = String("color : "+n);
}
function motionHandler(motion:int):void {
output.text= String("motion : "+motion);
}
function volHandler(index:int,vol:Number):void {
this["vol_"+index].text = String("index "+index+"/ volume :"+vol);
}





