【问题标题】:Adobe Flash Builder (1046: Type was not found or was not a compile-time constant)Adobe Flash Builder(1046:找不到类型或不是编译时常量)
【发布时间】:2014-07-04 11:04:52
【问题描述】:

我是第一次使用 Adob​​e Flash Builder,我正在尝试创建一个 Flex 项目。我将在 nodeJS 应用程序中嵌入 Flash 游戏,所以我使用https://github.com/sinnus/socket.io-flash。 Socket.io-flash 需要 websocketJS,我已将 socket.io-flash 文件夹(直接来自 github)和 websocketJS 文件夹(也来自 github)添加到 Flash Builder 的源路径(因此文件应该在它们被识别时被识别)是进口的 - 他们是)。我收到两个导入的错误:

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

还有……

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

就像我说的,导入行很好(那里没有抛出错误)-错误来自方法声明-这是我的 .mxml 文件:

<?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>

我已经用 '**' 封装了引发错误的行(由于某种原因,导入的内容有问题)。在我的 Flash Builder 项目中,libs 文件夹、websocketJS 文件夹和 socket.io-flash 文件夹中都有,它们都已添加到源路径中。任何帮助将不胜感激 - 谢谢!

【问题讨论】:

    标签: actionscript-3 flash sockets flash-builder mxml


    【解决方案1】:

    函数“logMessage”根本没有定义。使用“trace”作为替代(例如 trace(event.type + ":" + event.text);

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-03-17
      相关资源
      最近更新 更多