<?xml version="1.0" encoding="utf-8"?>
<mx:Canvas
xmlns:mx="http://www.adobe.com/2006/mxml"
>
<mx:Script>
<![CDATA[
import org.red5.net.FMSConnection ;
import org.red5.net.User ;
import mx.binding.utils.BindingUtils;
import mx.managers.CursorManager;
public var nc:NetConnection ;
public var userinfo:User = new User ;
public var shareURL:String = "" ;
private var oX:Number ;
private var oY:Number ;
private var nX:Number ;
private var nY:Number ;
private var soChat:SharedObject ;
private var mX:Number;
private var mY:Number;
private var IsDown:Boolean=false;
[Bindable] public var _lineSize:int=3;
[Bindable] public var _lineColor:uint=0xff0000;
public function init():void
{
userinfo.name = "admin" ;
BindingUtils.bindProperty(this,"_lineSize",hs,"value");
BindingUtils.bindProperty(this,"_lineColor",cp,"selectedColor");
NetConnection.defaultObjectEncoding=flash.net.ObjectEncoding.AMF3;
SharedObject.defaultObjectEncoding=flash.net.ObjectEncoding.AMF3;
nc=new FMSConnection();
nc.addEventListener( "success", connectionSuccessHandler );
nc.connect(shareURL);//连接Red5服务器
this.graphics.beginFill(0xffffff);
this.graphics.drawRect(0,0,this.width,this.height);
this.graphics.endFill();
if(this.userinfo.name=="admin")
{
myPanel.addEventListener(MouseEvent.MOUSE_DOWN,onMouseDown);
myPanel.addEventListener(MouseEvent.MOUSE_UP,onMouseUp);
myPanel.addEventListener(MouseEvent.MOUSE_MOVE,onMouseMove);
}
}
private function connectionSuccessHandler( event:Event ):void
{
soChat = SharedObject.getRemote( "videoConferenceChat", nc.uri, false );
soChat.client = this;
soChat.connect(nc);
}
private function onMouseDown(event:MouseEvent):void
{
IsDown = true ;
this.oX=myPanel.mouseX;
this.oY=myPanel.mouseY;
soChat.send("onDown",oX,oY);
}
private function onMouseUp(event:MouseEvent):void
{
IsDown=false;
soChat.send("onUp");
}
private function onMouseMove(event:MouseEvent):void
{
if(IsDown)
{
this.nX=myPanel.mouseX;
this.nY=myPanel.mouseY;
soChat.send("onDraw",nX,nY);
}
}
public function onDown(mX:Number,mY:Number):void
{
//this.graphics.lineStyle(Number(this.CBox.selectedItem),this.cpicker.selectedColor , 1);
trace("("+mX+","+mY+")") ;
this.mX=mX ;
this.mY=mY ;
//this.graphics.moveTo(mX, mY);
//this.addEventListener(MouseEvent.MOUSE_MOVE, onMouseMove);
}
public function onDraw(mX:Number,mY:Number):void
{
// this.graphics.lineTo(mX, mY);
trace("("+mX+","+mY+")") ;
var x:Number = this.mX;
var y:Number = this.mY;
myPanel.graphics.lineStyle(_lineSize,_lineColor,1);
myPanel.graphics.moveTo(x,y);
myPanel.graphics.lineTo(mX,mY);
this.mX=mX;
this.mY=mY;
}
public function onUp():void
{
//this.removeEventListener(MouseEvent.MOUSE_MOVE, onMouseMove);
}
//清除白板
public function onClear():void
{
this.graphics.lineStyle(0,0,0);
this.graphics.beginFill(0xffffff,1);
this.graphics.drawRect(0,0,this.width,this.height);
this.graphics.endFill();
}
private function sendClear():void
{
soChat.send("onClear");
}
]]>
</mx:Script>
<mx:Panel width="100%" height="100%">
<mx:Canvas id="myPanel" x="113.5" y="83" width="100%" height="90%" buttonMode="true" borderStyle="outset">
</mx:Canvas>
<mx:HBox width="100%">
<mx:Button label="清空" click="myPanel.graphics.clear();"/>
<mx:Button label="申请"/>
<mx:Button label="同意" enabled="false"/>
<mx:Button label="拒绝" enabled="false"/>
</mx:HBox>
<mx:HSlider id="hs" value="{_lineSize}"/>
<mx:ColorPicker id="cp" selectedColor="{_lineColor}"/>
</mx:Panel>
</mx:Canvas>