Aquí mas detallado..
Código actionscript:
Ver originalimport flash.events.Event;
import flash.display.MovieClip;
/**
* Array para guardar los objetos creados
*/
var store:Array = [];
/**
*Creamos los objetos desde un MovieClip en la libreria y los ponemos en el stage de modo random
*/
for (var i:int = 0; i<5; i++)
{
var tmp:ball = new ball();
store.push( tmp );
/*Damos un nombre para poder acceder al clip fuera del for */
tmp.name = "ball"+i;
tmp.x = Math.random() * stage.stageWidth;
tmp.y = Math.random() * stage.stageHeight;
addChild( tmp );
}
/*
* Accedemos a un objeto por su nombre
*/
var ball2:MovieClip = getChildByName('ball2') as MovieClip;
var ranx;int;
var rany:int;
/*
* Listener para animar un objeto solo como ejemplo
*/
addEventListener(Event.ENTER_FRAME, moveIt);
function moveIt(e:Event)
{
ball2.x += ((ranx-ball2.x)/10);
ball2.y += ((rany-ball2.y)/10);
if (Math.round(ball2.x) == ranx || Math.round(ball2.y) == rany) {
moveAll();
newcoords();
}
}
/*
* Accedemos a los Objetos guardados en el array..
*/
function moveAll()
{
for each ( var ball:MovieClip in store)
{
ball.x = Math.random() * stage.stageWidth;
ball.y = Math.random() * stage.stageHeight;
}
}
/*
* funcion de ayuda para generar nuevas coordenadas..
*/
function newcoords() {
ranx = Math.round((Math.random ()*stage.stageWidth));
rany = Math.round ((Math.random ()*stage.stageHeight));
}