Toribash
Original Post
How do you access properties of an instance from a class residing in a seperate class
Actionscript 3.0:

package
{
import flash.events.*;
import flash.display.Sprite;
import flash.display.Bitmap;
import flash.display.BitmapData;

public class ParticleAttractors extends Sprite
{
public var i:int;
public var j:int;

public var VX:Number;
public var VY:Number;

public var particle:Particle;
public var particles:Array;

public var attractor:Attractor;
public var attractors:Array;

public var repellor:Repellor;
public var repellors:Array;

public var VXarr:Array;
public var VYarr:Array;



public var isDown:Boolean;


public function ParticleAttractors():void
{

isDown = false;

VX = 0;
VY = 0;

VYarr = new Array();
VXarr = new Array();

particles = new Array();



addAttractors();
addRepellors();

stage.addEventListener(MouseEvent.MOUSE_DOWN, clicked, false, 0, true);


stage.addEventListener(MouseEvent.MOUSE_UP, unclicked, false, 0, true);


//add that enter frame thingy

addEventListener(Event.ENTER_FRAME, update, false, 0, true);
}

//add the particles and assign them to arrays

function clicked(e:MouseEvent):void
{
isDown = true;
}
function unclicked(e:MouseEvent):void
{
isDown = false;
}



function addParticles():void
{


particle = new Particle();
addChild(particle);

particle.x = mouseX;
particle.y = mouseY;

particles.push(particle);

VXarr.push(0);
VYarr.push(0);


}

//add the attractors and assign them to arrays

function addAttractors():void
{
attractors = new Array();

for (i = 0; i < 20; ++i)
{
attractor = new Attractor();
addChild(attractor);

attractor.x = Math.random() * stage.stageWidth;
attractor.y = Math.random() * stage.stageHeight;

attractors.push(attractor);
}
}

function addRepellors():void
{
repellors = new Array();

for (i = 0; i < 20; ++i)
{
repellor = new Repellor();
addChild(repellor);

repellor.x = Math.random() * stage.stageWidth;
repellor.y = Math.random() * stage.stageHeight;

repellors.push(repellor);
}
}

function update(e:Event):void
{
var dx:Number;
var dy:Number;
var nag:Number;
var fx:Number;
var fy:Number;
var damping:Number = 0.7;
var coef:Number = 15;



for (i = 0; i < particles.length; ++i)
{
particles[i].x += VXarr[i];
particles[i].y += VYarr[i];
fx = 0;
fy = 0;

for (j = 0; j < attractors.length; ++j)
{
dx = particles[i].x - attractors[j].x;
dy = particles[i].y - attractors[j].y;

nag = dx * dx + dy * dy + 1.;

fx -= coef * dx / nag;
fy -= coef * dy / nag;
}

for (j = 0; j < repellors.length; ++j)
{
dx = particles[i].x - repellors[j].x;
dy = particles[i].y - repellors[j].y;

nag = dx * dx + dy * dy + 1.;

fx += coef * dx / nag;
fy += coef * dy / nag;
}

if (!isDown)
{
dx = particles[i].x - mouseX;
dy = particles[i].y - mouseY;

nag = dx * dx + dy * dy + 1.;

fx += coef * dx / (nag * 2);
fy += coef * dy / (nag * 2);
}


VXarr[i] += fx;
VYarr[i] += fy;
if (particles[i].x < 0)
{
VXarr[i] *= -damping;
particles[i].x = 0;
}

if (particles[i].y < 0)
{
VYarr[i] *= -damping;
particles[i].y = 0;
}
if (particles[i].x > stage.stageWidth)
{
VXarr[i] *= -damping;
particles[i].x = stage.stageWidth;
}
if (particles[i].y > stage.stageHeight)
{
VYarr[i] *= -damping;
particles[i].y = stage.stageHeight;
}
if (particles[i].alph < 0.1)
{
particles.splice(i,1);
VXarr.splice(i,1);
VYarr.splice(i,1);
}
}

if (isDown)
{
addParticles();
}


}
}
}

If I wanted to access the property of each individual instance of the array in the for loop [i] how would I access and modify its properties, such as location, alpha, sub-class, etc?
eeerrrrmmm......shit on it? what is it?

USER WAS INFRACTED FOR THIS POST (USELESS POST)
Last edited by Mosier; Apr 3, 2009 at 12:10 AM.