Hello i am trying to open socket in flash.So i followed one tutorial but i got errors:
package com.game.game
{
import flash.net.socket;
import flash.events.*;
public dynamic class game
{
var mysocket:Socket = new Socket();
Security.allowDomain("*");
mysocket.addEventListener(Event.CONNECT, onConnect);
mysocket.addEventListener(Event.CLOSE, onClose);
mysocket.addEventListener(IOErrorEvent.IO_ERROR, onError);
mysocket.addEventListener(ProgressEvent.SOCKET_DATA, onResponse);
mysocket.addEventListener(SecurityErrorEvent.SECURITY_ERROR, onSecError);
mysocket.connect("hejp.co.uk", 80);
}
}
i got these errors:
1120: Access of undefined property mysocket.
1120: Access of undefined property onConnect.
1120: Access of undefined property mysocket.
1120: Access of undefined property onClose.
1120: Access of undefined property mysocket.
1120: Access of undefined property onError.
1120: Access of undefined property mysocket.
1120: Access of undefined property onResponse.
1120: Access of undefined property mysocket.
1120: Access of undefined property onSecError.
1120: Access of undefined property mysocket.
The class 'com.game.game.game' must subclass 'flash.display.MovieClip' since it is linked to a library symbol of that type.
Must i import something ???
Any ideas ?
It looks like you have the correct code for sockets, but it needs to be inside of a method. If you put the code to instantiate the socket inside of the constructor method, then you will connect to the socket when you instantiate the class. Alternatively, You could put the socket code inside a different public method that could be called from outside the class.
You may also need to state the scope of your class properties and methods by stating public or private at their declaration.
You also need to declare each of the listener functions, otherwise the socket won’t have functions to connect to.