simb / FlashSocket.IO

Library to help Flash, Flex and ActionScript clients connect to Socket.IO servers.
211 stars 74 forks source link

IWebSocketWrapper reference #4

Closed ldsang closed 13 years ago

ldsang commented 13 years ago

Hey I've been trying to compile the FlashSocketDemo.mxml file that you have here and I keep getting this error: "Error: Interface IWebSocketWrapper was not found". Here's my compile command:

mxmlc M:(source_path)\FlashSocketDemo.mxml -library-path+=M:(source_path)\libs\as3corelib.swc

I went through the files and IWebSocketWrapper is only referenced in one file in FlashSocket.as on line 23: "public class FlashSocket extends EventDispatcher implements IWebSocketWrapper". Is that supposed to be referenced anywhere else? Or am I compliling it incorrectly? Thanks.

Darryl

simb commented 13 years ago

Hey There,

The problem you are having is that this library is dependent on the websocket library that socket.io uses. The source code for that library is submoduled in the support folder.

However if you would like to just use the alpha swc, I just uploaded it to the downloads section for this project. I'll update the readme to reflect the build requirements.

Usage has changed from what is in the current FlashSocket.IO-Demo repository. Normal messages sent from the server still come in using the FlashSocketEvent.MESSAGE event. But custom events that have been added in 0.7 of Socket.IO have their own events. Usage looks like this in your Actionscript

protected function application1_creationCompleteHandler(event:FlexEvent):void { socket = new FlashSocket("dev.wordwars.net"); socket.addEventListener(FlashSocketEvent.CONNECT, onConnect); socket.addEventListener(FlashSocketEvent.MESSAGE, onMessage); socket.addEventListener(FlashSocketEvent.IO_ERROR, onError); socket.addEventListener(FlashSocketEvent.SECURITY_ERROR, onError);

            socket.addEventListener("game", onGame);
        }

With this socket.io server

io.sockets.on('connection', function (socket) { console.log('socket connected'); socket.send('a quick msg');

socket.emit('game', { game: currentGame });

});

A message would be sent 'a quick msg' and flash would call the onMessage handler above. Then emit sends a custom event called game. We add a game event handler in the AS3 example above.

I know this is crude but I wont get a chance to update the demo tonight and if you are trying to be productive with this I want you to have the info you need.

ldsang commented 13 years ago

Thanks for the quick response. So for the websocket library, I notice in the socket.io installation there is a websocket.js file in the path "socket.io/lib/transports" and a websocket.js file in the path "socket.io/lib-cov/transports". In addition there seems to be an entire project here on github and I'm not sure which one I'm actually supposed to reference. Should I move one of those to the empty directory or install something? I actually have been trying to get this working, but am unclear on this aspect.

Also, I assume the download you are referring to is in the zip package you can download here, right? Or is the swc you updated available for download by itself? At any rate, I redownloaded the new zip file with the updated files and recompiled and am getting the same error. I assumed your comment meant I needed either the new alpha swc OR the websocket library, but I suspect I was mistaken as that didn't seem to compile. I did add the changes you outlined above to the mxml file and the socket.io server file. Thanks for your help.

simb commented 13 years ago

Hi,

I posted a copy of the swc, so you would not have to compile at all. https://github.com/downloads/simb/FlashSocket.IO/FlashSocket.IO_0.7.0-Alpha.swc

HTH, sim

ldsang commented 13 years ago

Please excuse me as this is my first time actually using mxml (I generally just use .as files directly with FlashDevelop) but how do you use an swc file without compiling a new swf? I tried google, but on the adobe page it defines swc as files that are compiled into an swf. Is there some other method I should use to include that without compiling?

And I did include it as a library file and recompile, and it created an swf but I got runtime actionscript errors upon running the swf.