I am trying to use https://github.com/Worlize/AS3WebSocket library. When I create Flex project everything ok, but when I create AS3 project it can't connect to a websocket server. Function SHA1.hashToBase64 (adobe.crypto library) inside Websocket class throws error:
[SWF] TestWS.swf - 506,881 bytes after decompression
typecheck com.adobe.crypto::SHA1$/hashToBase64()
outer-scope = [global Object$]
[com.adobe.crypto::SHA1$~[O] String[S] *[A] *[A] *[A] *[A] *[A] *[A]] {} ()
0:debugfile "/Users/turtle/work/as3corelib/project/src;com/adobe/crypto;SHA1.as"
[com.adobe.crypto::SHA1$~[O] String[S] *[A] *[A] *[A] *[A] *[A] *[A]] {} ()
2:debugline 100
[com.adobe.crypto::SHA1$~[O] String[S] *[A] *[A] *[A] *[A] *[A] *[A]] {} ()
4:getlocal0
[com.adobe.crypto::SHA1$~[O] String[S] *[A] *[A] *[A] *[A] *[A] *[A]] {} (com.adobe.crypto::SHA1$~[O])
5:pushscope
[com.adobe.crypto::SHA1$~[O] String[S] *[A] *[A] *[A] *[A] *[A] *[A]] {com.adobe.crypto::SHA1$~[O]} ()
6:pushbyte 0
[com.adobe.crypto::SHA1$~[O] String[S] *[A] *[A] *[A] *[A] *[A] *[A]] {com.adobe.crypto::SHA1$~[O]} (int[I])
8:convert_u
[com.adobe.crypto::SHA1$~[O] String[S] *[A] *[A] *[A] *[A] *[A] *[A]] {com.adobe.crypto::SHA1$~[O]} (uint[U])
9:setlocal 7
[com.adobe.crypto::SHA1$~[O] String[S] *[A] *[A] *[A] *[A] *[A] uint[U]] {com.adobe.crypto::SHA1$~[O]} ()
11:debug
[com.adobe.crypto::SHA1$~[O] String[S] *[A] *[A] *[A] *[A] *[A] uint[U]] {com.adobe.crypto::SHA1$~[O]} ()
16:debug
[com.adobe.crypto::SHA1$~[O] String[S] *[A] *[A] *[A] *[A] *[A] uint[U]] {com.adobe.crypto::SHA1$~[O]} ()
21:debug
[com.adobe.crypto::SHA1$~[O] String[S] *[A] *[A] *[A] *[A] *[A] uint[U]] {com.adobe.crypto::SHA1$~[O]} ()
26:debug
[com.adobe.crypto::SHA1$~[O] String[S] *[A] *[A] *[A] *[A] *[A] uint[U]] {com.adobe.crypto::SHA1$~[O]} ()
31:debug
[com.adobe.crypto::SHA1$~[O] String[S] *[A] *[A] *[A] *[A] *[A] uint[U]] {com.adobe.crypto::SHA1$~[O]} ()
36:debug
[com.adobe.crypto::SHA1$~[O] String[S] *[A] *[A] *[A] *[A] *[A] uint[U]] {com.adobe.crypto::SHA1$~[O]} ()
41:debugline 102
[com.adobe.crypto::SHA1$~[O] String[S] *[A] *[A] *[A] *[A] *[A] uint[U]] {com.adobe.crypto::SHA1$~[O]} ()
43:getglobalscope
[com.adobe.crypto::SHA1$~[O] String[S] *[A] *[A] *[A] *[A] *[A] uint[U]] {com.adobe.crypto::SHA1$~[O]} (global~[O])
44:getslot 1
[com.adobe.crypto::SHA1$~[O] String[S] *[A] *[A] *[A] *[A] *[A] uint[U]] {com.adobe.crypto::SHA1$~[O]} (com.adobe.crypto::SHA1$[O])
46:getlocal1
[com.adobe.crypto::SHA1$~[O] String[S] *[A] *[A] *[A] *[A] *[A] uint[U]] {com.adobe.crypto::SHA1$~[O]} (com.adobe.crypto::SHA1$[O] String[S])
47:callproperty com.adobe.crypto:SHA1::createBlocksFromString 1
[com.adobe.crypto::SHA1$~[O] String[S] *[A] *[A] *[A] *[A] *[A] uint[U]] {com.adobe.crypto::SHA1$~[O]} (Array[O])
50:coerce Array
[com.adobe.crypto::SHA1$~[O] String[S] *[A] *[A] *[A] *[A] *[A] uint[U]] {com.adobe.crypto::SHA1$~[O]} (Array[O])
52:setlocal2
[com.adobe.crypto::SHA1$~[O] String[S] Array[O] *[A] *[A] *[A] *[A] uint[U]] {com.adobe.crypto::SHA1$~[O]} ()
53:debugline 103
[com.adobe.crypto::SHA1$~[O] String[S] Array[O] *[A] *[A] *[A] *[A] uint[U]] {com.adobe.crypto::SHA1$~[O]} ()
55:findpropstrict com.adobe.crypto:SHA1::hashBlocks
[com.adobe.crypto::SHA1$~[O] String[S] Array[O] *[A] *[A] *[A] *[A] uint[U]] {com.adobe.crypto::SHA1$~[O]} (com.adobe.crypto::SHA1$~[O])
57:getlocal2
[com.adobe.crypto::SHA1$~[O] String[S] Array[O] *[A] *[A] *[A] *[A] uint[U]] {com.adobe.crypto::SHA1$~[O]} (com.adobe.crypto::SHA1$~[O] Array[O])
58:callproperty com.adobe.crypto:SHA1::hashBlocks 1
[com.adobe.crypto::SHA1$~[O] String[S] Array[O] *[A] *[A] *[A] *[A] uint[U]] {com.adobe.crypto::SHA1$~[O]} (flash.utils::ByteArray[O])
61:coerce flash.utils::ByteArray
[com.adobe.crypto::SHA1$~[O] String[S] Array[O] *[A] *[A] *[A] *[A] uint[U]] {com.adobe.crypto::SHA1$~[O]} (flash.utils::ByteArray[O])
63:setlocal3
[com.adobe.crypto::SHA1$~[O] String[S] Array[O] flash.utils::ByteArray[O] *[A] *[A] *[A] uint[U]] {com.adobe.crypto::SHA1$~[O]} ()
64:pushstring ""
[com.adobe.crypto::SHA1$~[O] String[S] Array[O] flash.utils::ByteArray[O] *[A] *[A] *[A] uint[U]] {com.adobe.crypto::SHA1$~[O]} (String~[S])
66:debugline 109
[com.adobe.crypto::SHA1$~[O] String[S] Array[O] flash.utils::ByteArray[O] *[A] *[A] *[A] uint[U]] {com.adobe.crypto::SHA1$~[O]} (String~[S])
68:coerce_s
[com.adobe.crypto::SHA1$~[O] String[S] Array[O] flash.utils::ByteArray[O] *[A] *[A] *[A] uint[U]] {com.adobe.crypto::SHA1$~[O]} (String~[S])
69:setlocal 4
[com.adobe.crypto::SHA1$~[O] String[S] Array[O] flash.utils::ByteArray[O] String~[S] *[A] *[A] uint[U]] {com.adobe.crypto::SHA1$~[O]} ()
71:debugline 110
[com.adobe.crypto::SHA1$~[O] String[S] Array[O] flash.utils::ByteArray[O] String~[S] *[A] *[A] uint[U]] {com.adobe.crypto::SHA1$~[O]} ()
73:getlocal3
[com.adobe.crypto::SHA1$~[O] String[S] Array[O] flash.utils::ByteArray[O] String~[S] *[A] *[A] uint[U]] {com.adobe.crypto::SHA1$~[O]} (flash.utils::ByteArray[O])
74:pushbyte 0
[com.adobe.crypto::SHA1$~[O] String[S] Array[O] flash.utils::ByteArray[O] String~[S] *[A] *[A] uint[U]] {com.adobe.crypto::SHA1$~[O]} (flash.utils::ByteArray[O] int[I])
76:setproperty position
[com.adobe.crypto::SHA1$~[O] String[S] Array[O] flash.utils::ByteArray[O] String~[S] *[A] *[A] uint[U]] {com.adobe.crypto::SHA1$~[O]} ()
78:debugline 111
[com.adobe.crypto::SHA1$~[O] String[S] Array[O] flash.utils::ByteArray[O] String~[S] *[A] *[A] uint[U]] {com.adobe.crypto::SHA1$~[O]} ()
80:pushbyte 0
[com.adobe.crypto::SHA1$~[O] String[S] Array[O] flash.utils::ByteArray[O] String~[S] *[A] *[A] uint[U]] {com.adobe.crypto::SHA1$~[O]} (int[I])
82:convert_i
[com.adobe.crypto::SHA1$~[O] String[S] Array[O] flash.utils::ByteArray[O] String~[S] *[A] *[A] uint[U]] {com.adobe.crypto::SHA1$~[O]} (int[I])
83:setlocal 5
[com.adobe.crypto::SHA1$~[O] String[S] Array[O] flash.utils::ByteArray[O] String~[S] int[I] *[A] uint[U]] {com.adobe.crypto::SHA1$~[O]} ()
85:jump 129
------------------------------------
MERGE FIRST B129: [com.adobe.crypto::SHA1$~[O] String[S] Array[O] flash.utils::ByteArray[O] String~[S] int[I] *[A] uint[U]] {com.adobe.crypto::SHA1$~[O]} ()
------------------------------------
B129: [com.adobe.crypto::SHA1$~[O] String[S] Array[O] flash.utils::ByteArray[O] String~[S] int[I] *[A] uint[U]] {com.adobe.crypto::SHA1$~[O]} ()
129:getlocal 5
[com.adobe.crypto::SHA1$~[O] String[S] Array[O] flash.utils::ByteArray[O] String~[S] int[I] *[A] uint[U]] {com.adobe.crypto::SHA1$~[O]} (int[I])
131:getlocal3
[com.adobe.crypto::SHA1$~[O] String[S] Array[O] flash.utils::ByteArray[O] String~[S] int[I] *[A] uint[U]] {com.adobe.crypto::SHA1$~[O]} (int[I] flash.utils::ByteArray[O])
132:getproperty length
[com.adobe.crypto::SHA1$~[O] String[S] Array[O] flash.utils::ByteArray[O] String~[S] int[I] *[A] uint[U]] {com.adobe.crypto::SHA1$~[O]} (int[I] uint[U])
134:iflt 89
------------------------------------
MERGE FIRST B89: [com.adobe.crypto::SHA1$~[O] String[S] Array[O] flash.utils::ByteArray[O] String~[S] int[I] *[A] uint[U]] {com.adobe.crypto::SHA1$~[O]} ()
------------------------------------
[com.adobe.crypto::SHA1$~[O] String[S] Array[O] flash.utils::ByteArray[O] String~[S] int[I] *[A] uint[U]] {com.adobe.crypto::SHA1$~[O]} ()
138:debugline 117
[com.adobe.crypto::SHA1$~[O] String[S] Array[O] flash.utils::ByteArray[O] String~[S] int[I] *[A] uint[U]] {com.adobe.crypto::SHA1$~[O]} ()
140:findpropstrict mx.utils::Base64Encoder
[com.adobe.crypto::SHA1$~[O] String[S] Array[O] flash.utils::ByteArray[O] String~[S] int[I] *[A] uint[U]] {com.adobe.crypto::SHA1$~[O]} (Object~[A])
142:constructprop 14 0
[com.adobe.crypto::SHA1$~[O] String[S] Array[O] flash.utils::ByteArray[O] String~[S] int[I] *[A] uint[U]] {com.adobe.crypto::SHA1$~[O]} (*[A])
145:coerce mx.utils::Base64Encoder
Connection Failure: There was an error while parsing the following HTTP Header line:
Sec-WebSocket-Accept: k9NwkeRGtpHKwr+kcSk29tHaAbs=
Disconnected
Any ideas why?
I downloaded the as3corelib.swc being used by that project, and ran the following code.
In addition to your output, which basically says Flash Player threw an error trying to construct a new
Base64Encoder
object, I got the following output.It seems to be a known issue with as3corelib that was never resolved.
However, this dependency is also open source, so I just downloaded Base64Encoder.as, and added it to my project. After this, the code compiled fine. This should work for your project, as well.