Difference between revisions of "Server-monitor.as"

From Organic Design wiki
(add actionscript)
 
({{as}})
 
(66 intermediate revisions by 2 users not shown)
Line 1: Line 1:
// Instantiate the ball from classes supplied by swf.php
+
// Server monitor{{as}}
attachMovie( 'triangle', 'ball', 1 );
+
#include "debug.as"
 +
 +
echo( 'Begin: Hello world!', 'ff0000' );
  
// Set ball scale & colour
+
socket = new XMLSocket();
ball._xscale = ball._yscale = 50;
+
var value = 0;
col = new Color( ball );
 
col.setTransform( { rb:0x22, gb:0xff, bb:0 } );
 
  
// Initialise dynamics
+
// Connect to our host to establish stream
x = 0.0; y = 0.0;
+
if ( socket.connect( 'monitor.cs.auckland.ac.nz', 60180 ) ) echo( 'Connecting...', '00ff00' );
vx = 2.0; vy = 0.0;
+
else echo( 'Could not initialise connection!', 'ff0000' );
mx = 2.0; my = 12.0;
+
 
 +
// When connected, send login info
 +
socket.onConnect = function( success ) {
 +
    if ( success ) {
 +
        echo( 'Connected!', '00ff00' );
 +
        sendMessage( 'Hello?' );
 +
        }
 +
    else echo( 'Connection failed!', 'ff0000' );
 +
    };
 +
 
 +
// Decode incoming message
 +
socket.onData = function( data ) {
 +
    echo( 'Message received:', '00ff00' );
 +
    echo( data, 'ffff00' );
 +
    _root.value += data;
 +
    };
 +
 
 +
// Send a message to the associated peer
 +
function sendMessage( content ) {
 +
    echo( 'Sending message: "'+content+'"', '00ff00' );
 +
    _root.socket.send( content + String.fromCharCode(13,10,13,10) );
 +
    }
 +
 
 +
#include "bar-graph.as"
 +
 
 +
createSymbol( this, 'barGraph', 'myGraph', 0 );
  
// Dynamics (called each frame)
 
 
function reduce() {
 
function reduce() {
x += vx; y += vy; vy += 0.5;
+
    // graph the value and reset the accumulator
if ( vy > my ) vy = my;
+
    myGraph.rotate( _root.value );
if ( x < 0 ) { x = 0; vx = mx; }
+
    _root.value = 0;
if ( x > 200 ) { x = 200.0; vx = -mx; }
+
    }
if ( y > 200 ) { vy = -my; y = 200.0; }
 
ball._x = x; ball._y = y; ball._rotation += vx*2;
 
}
 

Latest revision as of 09:49, 14 March 2009

// Server monitorTemplate:As

  1. include "debug.as"

echo( 'Begin: Hello world!', 'ff0000' );

socket = new XMLSocket(); var value = 0;

// Connect to our host to establish stream if ( socket.connect( 'monitor.cs.auckland.ac.nz', 60180 ) ) echo( 'Connecting...', '00ff00' ); else echo( 'Could not initialise connection!', 'ff0000' );

// When connected, send login info socket.onConnect = function( success ) {

   if ( success ) {
       echo( 'Connected!', '00ff00' );
       sendMessage( 'Hello?' );
       }
   else echo( 'Connection failed!', 'ff0000' );
   };

// Decode incoming message socket.onData = function( data ) {

   echo( 'Message received:', '00ff00' );
   echo( data, 'ffff00' );
   _root.value += data;
   };

// Send a message to the associated peer function sendMessage( content ) {

   echo( 'Sending message: "'+content+'"', '00ff00' );
   _root.socket.send( content + String.fromCharCode(13,10,13,10) );
   }
  1. include "bar-graph.as"

createSymbol( this, 'barGraph', 'myGraph', 0 );

function reduce() {

   // graph the value and reset the accumulator
   myGraph.rotate( _root.value );
   _root.value = 0;
   }