I may be a bit backward in my thinking here, trying to fit my pre-OOP brain into OOP. I’m trying to access the instances of a class that was created with a loop, but am having trouble wrapping my brain around how I call the instances. Here are two classes that highlight my problem. Notice the inline comments. Thanks for any help!
//The document class. Imports the class (triangle graphic)
//and then tries to make a change to a specific instance every 2 sec.
package {
import flash.display.*;
import flash.events.*;
import flash.utils.Timer;
import flash.events.TimerEvent;
import flash.display.MovieClip;
public class DocClass extends MovieClip {
private var termList:Array=["MSP","SEA","LAX","LON","PAR"];
private var repeater:Timer = new Timer(2000, 0);
private var importedClass:ImportedClass;
public function DocClass() {
addClass();//call the func to build triangles
repeater.start();
repeater.addEventListener(TimerEvent.TIMER,doSomthng);
}
public function addClass() {
for (var i:int=0; i < termList.length; i++) {
importedClass=new ImportedClass(i * 30,i * 30);
importedClass.name=termList*;
addChild(importedClass);
}
}
public function doSomthng(e:TimerEvent) {
trace("timer has been called");
//HERE, I WANT TO DECREASE "LAX" ALPHA BY .1 EACH TIME
//TIMER FIRES HOW DO I ADDRESS OBJECT "LAX"?
//(THIS IS A SIMPLE REMAKE OF THE PROBLEM I'M HAVING.
//THE ESSENSE OF MY QUESTION IS,
//"HOW DO I PROGRAMMATICALLY ADDRESS
//A CLASS INSTANCE?"
}
}
}
//the imported class--just draws a sample triangle
package {
import flash.display.*;
import flash.display.MovieClip;
public class ImportedClass extends MovieClip {
public var Xpos:int;
public var Ypos:int;
public function ImportedClass(Xpos,Ypos) {
var tri:Sprite = new Sprite();
tri.graphics.lineStyle(1);
tri.graphics.beginFill(0x000000,1);
tri.graphics.moveTo(25,0);
tri.graphics.lineTo(50,25);
tri.graphics.lineTo(0,25);
tri.graphics.lineTo(25,0);
tri.graphics.endFill();
addChild(tri);
x=Xpos;
y=Ypos;
}
}
}