Skip to content

Pitch() & Catch()

Communication between 2 flash movies

Above, we have the catching SWF. Below, we have the pitching SWF. Type something in the text box and press “GO”.


pitch()

package com.drpunchlogic
{
    import flash.display.Sprite;
    import flash.events.MouseEvent;

	import flash.net.LocalConnection;

    import flash.events.StatusEvent;

    public class punchPitch extends Sprite
	{
// ---------------------------
		private var conn:LocalConnection;

        public function punchPitch()
		{
            conn = new LocalConnection();
            conn.addEventListener(StatusEvent.STATUS, onStatus);

			btn.addEventListener( MouseEvent.CLICK, pitch );
        }

        private function pitch( e:MouseEvent ):void {
            conn.send( "myConnection", "lcHandler", txt.text );
        }

        private function onStatus( e:StatusEvent ):void {
            switch ( e.level ) {
                case "status":
                    trace("LocalConnection.send() succeeded");
                    break;
                case "error":
                    trace("LocalConnection.send() failed");
                    break;
            }
        }
// ---------------------------
    }
}

catch()

package com.drpunchlogic
{
    import flash.display.Sprite;
    import flash.net.LocalConnection;

    public class punchCatch extends Sprite {
        private var conn:LocalConnection;
        private var output:TextField;

        public function punchCatch()
		{
            conn = 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");
            }
        }

        public function lcHandler(msg:String):void
		{
            txt.htmlText = msg;
        }

    }
}

One Comment

  1. DrPunchman wrote:

    Not 100% sure on what the deal here is. The code seems to work 70% of the time. At first I thought it was the player version, or wordpress. Now I am wondering if it is something else… Anywho…

    Wednesday, December 9, 2009 at 3:04 PM | Permalink

Post a Comment

Your email is never published nor shared. Required fields are marked *
*
*