-
AS2 Equivalent of This AS3 Script?
So I want to make a Flash LAN game, and with AS3 I got this script to work, but I want an AS2 equivalent of it, if possible. I know it should be a simple alteration, can anyone help at all?
import flash.events.NetStatusEvent;
import flash.net.NetConnection;
import flash.net.NetGroup;
import flash.net.GroupSpecifier;
import flash.events.MouseEvent;
var nc:NetConnection;
var group:NetGroup;
nc = new NetConnection();
nc.addEventListener(NetStatusEvent.NET_STATUS, netStatus);
nc.connect("rtmfp:");
function netStatus(event:NetStatusEvent):void
{
switch (event.info.code)
{
// The connection attempt succeeded
case "NetConnection.Connect.Success" :
setupGroup();
break;
// The NetGroup is successfully constructed and authorized to function.
case "NetGroup.Connect.Success" :
// Do nothing
break;
// A new group posting is received
case "NetGroup.Posting.Notify" :
mc.x = event.info.message.x;
mc.y = event.info.message.y;
break;
// user joins?
case "NetGroup.Neighbor.Connect" :
break;
}
}
mc.addEventListener(MouseEvent.MOUSE_DOWN, drag);
mc.addEventListener(MouseEvent.MOUSE_UP, drop);
// Drag the object
function drag(e:MouseEvent):void
{
this.stage.addEventListener(MouseEvent.MOUSE_MOVE, moveMe);
}
// Move the object in accordind of the mouse position
var obj:Object = {};
function moveMe(e:MouseEvent):void
{
mc.x = e.stageX;
mc.y = e.stageY;
obj.x = mc.x;
obj.y = mc.y;
// Set the peerID to a group address suitable for use with the sendToNearest() method.
obj.sender = group.convertPeerIDToGroupAddress(nc.nearID);
// Sends a message to all members of a group.
group.post(obj);
}
// Drop the object and send a message to all members of a group.
function drop(e:MouseEvent):void
{
this.stage.removeEventListener(MouseEvent.MOUSE_MO VE, moveMe);
// Save the current movieclip position;
obj.x = mc.x;
obj.y = mc.y;
// Set the peerID to a group address suitable for use with the sendToNearest() method.
obj.sender = group.convertPeerIDToGroupAddress(nc.nearID);
// Sends a message to all members of a group.
group.post(obj);
}
// Create a group
function setupGroup():void
{
// Create a new Group Specifier object
var groupspec:GroupSpecifier = new GroupSpecifier("test");
// Enable posting
groupspec.postingEnabled = true;
// Specifies whether information about group membership can be exchanged on IP multicast sockets
groupspec.ipMulticastMemberUpdatesEnabled = true;
// Causes the associated NetStream or NetGroup to join the specified IP multicast group and listen to the specified UDP port.
groupspec.addIPMulticastAddress("225.225.0.1:30000 ");
// Constructs a NetGroup on the specified NetConnection object and joins it to the group specified by groupspec.;
group = new NetGroup(nc,groupspec.groupspecWithAuthorizations( ));
// Set the NET_STATUS event listener
group.addEventListener(NetStatusEvent.NET_STATUS,n etStatus);
}
myButton.addEventListener(MouseEvent.CLICK, myButtonClick);
function myButtonClick(ev:MouseEvent):void
{
trace("myButton has been clicked.");
}
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|