0
votes

I am using Adobe Flash Builder for the first time, and I am trying to create a Flex project. I am going to be embedding a flash game in a nodeJS app, so I am using https://github.com/sinnus/socket.io-flash. Socket.io-flash requires websocketJS, and I have added both the socket.io-flash folder (straight from github), and the websocketJS folder (also from github) to Flash Builder's source path (so the files should be getting recognized when they are imported - and they are). I am getting this error for two of the imports:

1046: Type was not found or was not a compile-time constant: SocketIOEvent.

and...

1046: Type was not found or was not a compile-time constant: SocketIOErrorEvent.

Like I said, the import lines are fine (no errors being thrown there) - the errors come from the method declarations - here is my .mxml file:

<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
               xmlns:s="library://ns.adobe.com/flex/spark" 
               xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600">
    <fx:Declarations>
        <!-- Place non-visual elements (e.g., services, value objects) here -->
    </fx:Declarations>
    <s:VGroup>
        <s:TextArea id="textArea" width="300" height="300"/>
        <s:Button label="Connect" click="onConnectClick()"/>
        <s:Button label="Send" click="onSendClick()"/>
        <s:Button label="Disconnect" click="onDisconnectClick()"/>
    </s:VGroup>
    <fx:Script>
        <![CDATA[
            import com.adobe.serialization.json.JSON;
            import io.socket.flash.ISocketIOTransport;
            import io.socket.flash.ISocketIOTransportFactory;
            import io.socket.flash.SocketIOErrorEvent;
            import io.socket.flash.SocketIOEvent;
            import io.socket.flash.SocketIOTransportFactory;
            import io.socket.flash.WebsocketTransport;
            import io.socket.flash.XhrPollingTransport;

            private var _socketIOTransportFactory:ISocketIOTransportFactory = new SocketIOTransportFactory();
            private var _ioSocket:ISocketIOTransport;

            private function onConnectClick():void
            {
                _ioSocket = _socketIOTransportFactory.createSocketIOTransport(XhrPollingTransport.TRANSPORT_TYPE, "localhost:9000/socket.io", this);
                _ioSocket.addEventListener(SocketIOEvent.CONNECT, onSocketConnected);
                _ioSocket.addEventListener(SocketIOEvent.DISCONNECT, onSocketDisconnected);
                _ioSocket.addEventListener(SocketIOEvent.MESSAGE, onSocketMessage);
                _ioSocket.addEventListener(SocketIOErrorEvent.CONNECTION_FAULT, onSocketConnectionFault);
                _ioSocket.addEventListener(SocketIOErrorEvent.SECURITY_FAULT, onSocketSecurityFault);
                _ioSocket.connect();
            }

            **private function onSocketConnectionFault(event:SocketIOErrorEvent):void**
            {
                logMessage(event.type + ":" + event.text);
            }

            **private function onSocketSecurityFault(event:SocketIOErrorEvent):void**
            {
                logMessage(event.type + ":" + event.text);
            }

            private function onDisconnectClick():void
            {
                _ioSocket.disconnect();
            }

            **private function onSocketMessage(event:SocketIOEvent):void**
            {
                if (event.message is String)
                {
                    logMessage(String(event.message));
                }
                else
                {
                    logMessage(JSON.encode(event.message));
                }
            }

            private function onSendClick():void
            {
                _ioSocket.send({type: "chatMessage", data: "Привет!!!"});
                _ioSocket.send({type: "chatMessage", data: "Delirium tremens"});
                _ioSocket.send("HELLO!!!");
            }

            **private function onSocketConnected(event:SocketIOEvent):void**
            {
                logMessage("Connected" + event.target);
            }

            **private function onSocketDisconnected(event:SocketIOEvent):void**
            {
                logMessage("Disconnected" + event.target);
            }

            private function logMessage(message:String):void
            {
                textArea.text = textArea.text + message + "\n";
            }
        ]]>
    </fx:Script>
</s:Application>

I have encased the lines where the errors are thrown from with '**' (it is having trouble with what is being imported for some reason). In my Flash Builder project I have, in the libs folder, the websocketJS folder, and the socket.io-flash folder, and they have both been added to the source path. Any help would be greatly appreciated - thanks!

1

1 Answers

0
votes

The function "logMessage" is simply not defined. Use "trace" as alternative (e.g. trace(event.type + ":" + event.text);