Hi,
I’m creating instances of a movieclip in the library dynamically, then i want to animate them (make them drop from the top to bottom). But I can’t figure out how to access them in my array.
They are in there, they come up in a trace, but using a loop through them (on enter frame) and trying to change y value doesn’t work? I have my array registered at the top of the class, and get no errors…
// randomly create treasures with timer (WILL MOVE TREASURES WITH TIMER ASWELL)
public function createTreasures(){
var rand:Number = (Math.ceil(Math.random()*2000))
var timer:Timer = new Timer(rand);
timer.addEventListener(TimerEvent.TIMER,timerF);
timer.start();
treasures = new Array();
function timerF(event:TimerEvent):void{
var treasure:MovieClip = new Treasure();
treasure.x = (Math.ceil(Math.random()*800));
treasure.y = 0;
//random treasure type
treasure.type = Math.ceil(Math.random()*5);
treasure.gotoAndStop(treasure.type);
treasure.speedY = Math.random() * 5 + 2;
treasure.inAir = true;
treasure.width = 20.0;
treasure.height = 40.0;
//keep treasures with min/max boudary
if (treasure.x<100){
treasure.x = treasure.x + 100;
}
else if(treasure.x>700){
treasure.x = treasure.x -100;
}
//add to stage
addChild(treasure);
//push into array
treasures.push(treasure);
}
}
//loop through treasures
public function moveTreasures(timeDiff){
for(var i:int=0;i<treasures.length;i++){
// add to treasures y value
treasures*.y = treasures.y + 100;
}
}
spank you