Difference between revisions of "Server-monitor.as"

From Organic Design wiki
(undo that - they're lines not rects :-|)
({{as}})
 
(35 intermediate revisions by 2 users not shown)
Line 1: Line 1:
// blank movie clip
+
// Server monitor{{as}}
createEmptyMovieClip( 'graph', 1 );
+
#include "debug.as"
with (graph) {
+
_x = 0;
+
echo( 'Begin: Hello world!', 'ff0000' );
_y = 0;
 
_height = _root.width;
 
_width = _root.height;
 
lineStyle( 2, 0x00ff00 );
 
}
 
  
for ( i = 0; i < 800; i += 3 ) {
+
socket = new XMLSocket();
graph.moveTo( i, 0 );
+
var value = 0;
graph.lineTo( i, Math.random * _root.height );
 
}
 
graph.nextFrame();
 
  
// Textbox
+
// Connect to our host to establish stream
createTextField( 'rc', 1, 0, 0, width, height );
+
if ( socket.connect( 'monitor.cs.auckland.ac.nz', 60180 ) ) echo( 'Connecting...', '00ff00' );
with (rc) {
+
else echo( 'Could not initialise connection!', 'ff0000' );
_alpha = 30;
 
selectable = true;
 
_quality = 'BEST';
 
border = false;
 
multiline = true;
 
wordWrap = true;
 
html = true;
 
htmlText = '<font color="#00ff00">Hello World :-)</font>';
 
}
 
  
 +
// 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 );
  
 
function reduce() {
 
function reduce() {
}
+
    // graph the value and reset the accumulator
 +
    myGraph.rotate( _root.value );
 +
    _root.value = 0;
 +
    }

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;
   }