none
How to Send Joint X and Y's to adobe flash. RRS feed

  • Question

  • I understand that this is strickly a place to ask about nui. But I find flash easier to make interfaces in for me.

    I already know how to track objects Joints and get their x, y, and z.

    but how do I send the information to any other application outside of wpf?

    Socket Server? Writing to an XML?

    Please Let me know what you think.

    Friday, June 24, 2011 12:02 AM

Answers

  • Host a WebBrowser control in WPF and use the InvokeScript method to call javascript methods to talk to your flash object hosted in the WebBrowser control.

    I've used this technique to control both AJAX applications (2.5 Gigapixel mosaic using SeaDragon AJAX) and Silverlight (Photosynth)


    Windows Live Developer MVP - www.soulsolutions.com.au - follow http://twitter.com/bingmapsdev for latest news.
    Sunday, June 26, 2011 11:01 AM

All replies

  • Alright since I havent heard from you guys much I went ahead and broke my head for a couple hours and just got a little progress.

     

    Basically a method called sendMessage();

     

     public void sendMessage(string Message){

                System.Text.ASCIIEncoding encoding = new System.Text.ASCIIEncoding();

                try

                {

                    // This will bind us to the first IP address found on this computer

                    IPAddress localAddress = IPAddress.Parse("127.0.0.1");

     

                    // Define the kind of socket we want: Internet, Stream, TCP

                    Socket listenSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);

     

                    // Define the address we want to claim: the first IP address found earlier, at port 2200

                    IPEndPoint ipEndpoint = new IPEndPoint(localAddress, 3000);

     

                    // Bind the socket to the end point

                    listenSocket.Bind(ipEndpoint);

     

                    // Start listening, only allow 1 connection to queue at the same time

                    listenSocket.Listen(1);

     

                    // Start listening for connections -- the program loops forever

                    while (true)

                    {

                       // Console.WriteLine("Server is waiting on socket {0}", ipEndpoint);

     

                        // The program is suspended while waiting for an incoming connection.

                        // This is a synchronous TCP application

                        Socket handler = listenSocket.Accept();

     

                        // An incoming connection needs to be processed.

                        //Console.WriteLine("Received Connection from {0}", handler.RemoteEndPoint);

     

                       // Console.WriteLine("Sending message..");

                        handler.Send(encoding.GetBytes(Message));

     

                        // End of the incomming connection

                       // Console.WriteLine("Ending the connection");

                        handler.Close();

                    }

                }

                catch (Exception e)

                {

                    //Console.WriteLine("Caught Exception: {0}", e.ToString());

                }

            }

     

    Then in flash Main Document Class:

     

    package  {

    import flash.display.MovieClip;

    public class KinectFlash extends MovieClip {

    public function KinectFlash() {

    // constructor code

    var socket:CustomSocket = new CustomSocket("127.0.0.1", 3000);

    }

    }

    }

     

    import flash.errors.*;

    import flash.events.*;

    import flash.net.Socket;

     

    class CustomSocket extends Socket {

        private var response:String;

     

        public function CustomSocket(host:String = null, port:uint = 0) {

            super();

            configureListeners();

            if (host && port)  {

                super.connect(host, port);

            }

        }

     

        private function configureListeners():void {

            addEventListener(Event.CLOSE, closeHandler);

            addEventListener(Event.CONNECT, connectHandler);

            addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler);

            addEventListener(SecurityErrorEvent.SECURITY_ERROR, securityErrorHandler);

            addEventListener(ProgressEvent.SOCKET_DATA, socketDataHandler);

        }

     

        private function writeln(str:String):void {

            str += "\n";

            try {

                writeUTFBytes(str);

            }

            catch(e:IOError) {

                trace(e);

            }

        }

     

        private function sendRequest():void {

            trace("sendRequest");

           // response = "";

           // writeln("GET /");

            //flush();

        }

     

        private function readResponse():void {

            var str:String = readUTFBytes(bytesAvailable);

            response += str;

    trace(str);

        }

     

        private function closeHandler(event:Event):void {

            trace("closeHandler: " + event);

            trace(response.toString());

        }

     

        private function connectHandler(event:Event):void {

            trace("connectHandler: " + event);

            sendRequest();

        }

     

        private function ioErrorHandler(event:IOErrorEvent):void {

            trace("ioErrorHandler: " + event);

        }

     

        private function securityErrorHandler(event:SecurityErrorEvent):void {

            trace("securityErrorHandler: " + event);

        }

     

        private function socketDataHandler(event:ProgressEvent):void {

            trace("socketDataHandler: " + event);

            readResponse();

        }

    }

    But what happens is when I send the message my whole wpf application freezes.

    Im sending the message inside my  nui_SkeletonFrameReady();

     

    like this: sendMessage(joint.ID.ToString());

     

    I do receive the message in flash! but my wpf app freezes :/

     

    anyone know why?

    Friday, June 24, 2011 3:44 AM
  • Host a WebBrowser control in WPF and use the InvokeScript method to call javascript methods to talk to your flash object hosted in the WebBrowser control.

    I've used this technique to control both AJAX applications (2.5 Gigapixel mosaic using SeaDragon AJAX) and Silverlight (Photosynth)


    Windows Live Developer MVP - www.soulsolutions.com.au - follow http://twitter.com/bingmapsdev for latest news.
    Sunday, June 26, 2011 11:01 AM
  • Sargentsurg,

    SoulSolutions seems has posted a solution that seems workable. About your app freezing, though, what is the full callstack at which your app gets frozen, though?

    For example, is it during  handler.Send(encoding.GetBytes(Message)), or maybe during handler.Close()? Also, other details in callstack would give a hint as to whether there could be a deadlock between main UI thread waiting on a different thread and, if so, what might that other thread be doing to deadlock with main UI thread.

    Eddy


    I'm here to help
    Tuesday, June 28, 2011 11:56 PM