![](/img/trans.png)
[英]Flash AS3 - 1046: Type was not found or was not a compile-time constant:
[英]Adobe Flash Builder (1046: Type was not found or was not a compile-time constant)
我是第一次使用Adobe Flash Builder,並且正在嘗試創建Flex項目。 我將把Flash游戲嵌入到nodeJS應用程序中,所以我在使用https://github.com/sinnus/socket.io-flash 。 Socket.io-flash需要websocketJS,並且我已經在Flash Builder的源路徑中添加了socket.io-flash文件夾(直接來自github)和websocketJS文件夾(同樣來自github)(因此,當文件被識別時,進口-並且它們是。 對於兩個導入,我都收到此錯誤:
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文件夾中,並且它們都已添加到源路徑中。 任何幫助將不勝感激-謝謝!
根本沒有定義函數“ logMessage”。 使用“ trace”作為替代(例如trace(event.type +“:” + event.text);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.