user3503143
user3503143

Reputation: 391

Type was not found 'ServerSocketConnectEvent'

I'm new with actionscript and want to create a socket server and listen to it, here is my code:

package
{ 
  import flash.display.Sprite;
  import flash.net.ServerSocket; 
  import flash.events;
  import flash.events.ServerSocketConnectEvent;
  import flash.net.ServerSocket;
  import flash.net.Socket;

    public class one extends Sprite
    { 
        private static  var server:ServerSocket;
        private static  var client:Socket;

      public static function create() 
      {
        one.server = new ServerSocket();
        one.server.bind(8888);
        one.server.addEventListener(ServerSocketConnectEvent.CONNECT, one.serverConnectHandler);
        one.server.listen();
      }

      public static function serverConnectHandler(e:ServerSocketConnectEvent):void 
      {
        var socket:Socket = e.socket;
        one.client = socket;
      }

      public static function send(param1:String)
      {
        one.client.writeUTFBytes(param1);
      }
    }
}

When I compile it using mxmlc.exe -static-link-runtime-shared-libraries=true one.as but get the error:

C:\Users\Mark\Desktop\test program\one.as(23): col: 53 Error: Type was not found or was not a compile-time constant: ServerSocketConnectEvent.

Same exact problem was mentioned here but Can't I somehow point to those libraries during compilation? The only solution is to build application form adobe proffesional? I'm little lost.

Upvotes: 0

Views: 117

Answers (1)

VC.One
VC.One

Reputation: 15881

This is a simple error: Look at your imports.

import flash.net.ServerSocket; 
import flash.events; //this is the problem
import flash.events.ServerSocketConnectEvent;

You have use bad syntax when declaring the source paths of your imports. You should have received two errors, the second should say Error 1172: Definition flash:events could not be found.

import flash.events; //this is wrong syntax & does not load EVENTS Class (API)
import flash.events.*; //this is correct syntax to allow EVENTS Class

Start with import flash.+ ClassName. + ABC; ... where ABC; is a specific Name; or just use a generic *;

Solution:
So just replace import flash.events; with import flash.events.*; and it should work.

Upvotes: 0

Related Questions