Network structure 2

Code Actionscript 2.0

Frame action

// duplicate nodes
for (node = 1; node <= 8; node = node + 1) {
square0.duplicateMovieClip("square" + node, node);
_root["square" + node]._x = random(350);
_root["square" + node]._y = random(350);
}
square0._visible = 0;

// connect nodes
createEmptyMovieClip("lines", 100);
lines.lineStyle(0, 0x000000, 100);
for (k = 1; k < 8; k = k + 1) {
for (l = k + 1; l <= 8; l = l + 1) {
lines.moveTo(_root["square" + k]._x, _root["square" + k]._y);
lines.lineTo(_root["square" + l]._x, _root["square" + l]._y);
}
}

Code Actionscript 3.0

var Squares:Array = new Array(); // duplicate nodes for (var node = 1; node <= 8; node = node + 1) { //important: square has to be exported for actionscript //go to "linkage" in library menu Squares[node] = new squareObject(); Squares[node].x = int(Math.random()*350); Squares[node].y = int(Math.random()*350); addChild(Squares[node]); } square0.visible = false; // connect nodes var lines = new MovieClip(); lines.graphics.lineStyle(1, 0x000000, 1); for (var k = 1; k < 8; k = k + 1) { for (var l = k + 1; l <= 8; l = l + 1) { lines.graphics.moveTo(Squares[k].x, Squares[k].y); lines.graphics.lineTo(Squares[l].x, Squares[l].y); } } addChild(lines);

Description

This script randomly arranges the nodes of a network within the stage. In this example, each is connected to every other node with a line.

related to: Random arrangement,

Download

Right click: Flashfile AS 2.0 | Flashfile AS 3.0 | SWF-File


Share