Network structure 3

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;

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

Instance action

onClipEvent (load) {
speedx = random(5);
speedy = random(5);
}
onClipEvent (enterFrame) {
this._x = this._x + speedx;
this._y = this._y + speedy;
if (this._x > 400 - 18) {
this._x = 400 - 18;
speedx = -speedx;
}
if (this._x < 0) {
this._x = 0;
speedx = -speedx;
}
if (this._y > 400 - 18) {
this._y = 400 - 18;
speedy = -speedy;
}
if (this._y < 0) {
this._y = 0;
speedy = -speedy;
}
}

Code Actionscript 3.0

addEventListener(Event.ENTER_FRAME, enterFrame); var Squares:Array = new Array(); var Speedsx: Array = new Array(); var Speedsy: Array = new Array(); var lines; // 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); Speedsx[node] = int(Math.random()*5); Speedsy[node] = int(Math.random()*5); addChild(Squares[node]); } square0.visible = false; function enterFrame(event:Event) { for(var i= 1; i 400-18) { Squares[i].x = 400-18; Speedsx[i] = -Speedsx[i]; } if (Squares[i].x < 0) { Squares[i].x = 0; Speedsx[i] = -Speedsx[i]; } if (Squares[i].y > 400-18) { Squares[i].y = 400-18; Speedsy[i] = -Speedsy[i]; } if (Squares[i].y < 0) { Squares[i].y = 0; Speedsy[i] = -Speedsy[i]; } } if(lines != null) removeChild(lines); // connect nodes lines = new MovieClip(); lines.graphics.lineStyle(1, 0x000000, 1); lines.graphics.moveTo(Squares[1].x, Squares[1].y); for (node = 2; node <= 8; node = node + 1) { lines.graphics.lineTo(Squares[node].x, Squares[node].y); } addChild(lines); }

Description

This script randomly arranges the nodes of a network within the stage, while each is connected with a line. The nodes continuously move and bounce from the edges of the stage.

related to: Bouncing movement, Random arrangement,

Download

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


Share