LocalConnection working but in a strange way

Hi,

I am working in Adobe Flash CS3, AS3. I used this example to set up a localConnection:
http://blog.circlecube.com/2008/03/12/local-connection-actionscript-communicate-between-seperate-flash-files-tutorial/

The difference is the example is not in AS3 .as files so I created my own.

The problem is I have to have the function that is called from the send LocalConnection in the same scope as the receiving LocalConnection. This alone does not work, I then have to put the same function outside of the LocalConnection scope and that is the function that is actually called. If I get rid of either function the LocalConnection still connects but it cannot find the function.

Here are the two .as I use; both of them are almost the same:


package {
	import flash.display.Sprite;
	import flash.net.LocalConnection;
	import flash.events.StatusEvent;
	import flash.events.AsyncErrorEvent
	import flash.events.MouseEvent;
	
	public class BlueMain extends Sprite {
		private var sending_lc:LocalConnection;
 
		public function BlueMain() {
				createSendBtn();
				createSendRecieveConn();
		}
		private function createSendRecieveConn():void{
			// Receiving
			var receiving_lc:LocalConnection = new LocalConnection();
			//receive connection of specified name
			receiving_lc.connect("_fromRed");
			receiving_lc.addEventListener(AsyncErrorEvent.ASYNC_ERROR, onAsync);
			receiving_lc.client = this;
			//
			function recieveRedText(){
				trace("Never Traces")
			}
 
			sending_lc = new LocalConnection();
			sending_lc.addEventListener(StatusEvent.STATUS, onStatus);
		}
		
		public function recieveRedText(textRecieved:String){
			trace("textRecievedFromRed2= "+textRecieved)	
		}
		//
		protected function createSendBtn():void{
			var blueSendBtn:BlueSendBtn = new BlueSendBtn();
			blueSendBtn.x = 0;
			blueSendBtn.y = 0;
		  //rbRadioButton.addEventListener(Event.CHANGE, changeHandler);
			blueSendBtn.addEventListener(MouseEvent.CLICK, changeHandler);
			addChild(blueSendBtn);
			
			
			function changeHandler(event:MouseEvent):void {
	  		trace("BlueBtnClick:");
	  		//send through specified connection, call specified method, send specified parameter
				sending_lc.send("_fromBlue", "recieveBlueText", "I am text from blue");
			}
		}
		//
    private function onStatus(event:StatusEvent):void {
    	switch (event.level) {
	      case "status": 
	      	trace("LocalConnection.send() Blue succeeded");
	        break;
	      case "error":
	        trace("LocalConnection.send() Blue failed");
	        break;
      }
    }
    
    private function onAsync(asevent:AsyncErrorEvent):void {
     	trace("asEventBlue= "+asevent.error)	
    }
	}
}

package {
	import flash.display.Sprite;
	import flash.net.LocalConnection;
	import flash.events.StatusEvent;
	import flash.events.AsyncErrorEvent
	import flash.events.MouseEvent;
	
	public class RedMain extends Sprite {
		private var sending_lc:LocalConnection;
 
		public function RedMain() {
			createSendBtn();
			createSendRecieveConn();
		}
		
		private function createSendRecieveConn():void{
			// Receiving
			var receiving_lc:LocalConnection = new LocalConnection();
			//receive connection of specified name
			receiving_lc.connect("_fromBlue");
			receiving_lc.addEventListener(AsyncErrorEvent.ASYNC_ERROR  ,onAsync);
			receiving_lc.client = this;
			// Sending
			sending_lc = new LocalConnection();
			sending_lc.addEventListener(StatusEvent.STATUS, onStatus);
			
			function recieveBlueText(){
				trace("Never Traces")
			}	
		}
		
		public function recieveBlueText(textRecieved:String){
			trace("textRecievedFromBlue2= "+textRecieved)	
		}
		
		protected function createSendBtn():void{
			var blueSendBtn:RedSendBtn = new RedSendBtn();
			blueSendBtn.x = 0;
			blueSendBtn.y = 0;
		  //rbRadioButton.addEventListener(Event.CHANGE, changeHandler);
			blueSendBtn.addEventListener(MouseEvent.CLICK, changeHandler);
			addChild(blueSendBtn);
			
			
			function changeHandler(event:MouseEvent):void {
    		trace("RedBtnClick:");
    		//send through specified connection, call specified method, send specified parameter
				sending_lc.send("_fromRed", "recieveRedText", "I am text from Red");
			}
		}
		
		//
    private function onStatus(event:StatusEvent):void {
    	switch (event.level) {
	      case "status": 
	      	trace("LocalConnection.send() Red succeeded");
	        break;
	      case "error":
	        trace("LocalConnection.send() Red failed");
	        break;
      }
    }
     private function onAsync(asevent:AsyncErrorEvent):void {
     	trace("asEventRed= "+asevent.error)
    }
  }
}

To run these you will need to make a graphical movieclip with a linkage name of blueSendBtn and blueSendBtn respectively.

Thanks,
waffe