Some basic advice:
Do not nest functions inside other functions.
Most of the time, instance methods and properties should be private.
(certainly, they should
start out as private, ond only changed to public if absolutely necessary)
Declare properties within the class block;
define them in the constructor or within downstream methods.
Use the forum [as] tags to post formatted actionscript code.
Here's a compact version of your code, minus the stuff I couldn't validate and test.
Only 1 instance of each ObjectX class will be added to the displaylist.
ActionScript Code:
package
{
import flash.display.*;
import flash.events.*;
import flash.ui.*;
import flash.text.*;
import flash.utils.*;
public class Collectibles extends MovieClip
{
private var t:Timer;
private var delay:int;
private var repeat:int;
private var newObject:MovieClip;
private var objects:Array;
public function Collectibles()
{
objects = [{obj:Object1, val:20},
{obj:Object2, val:30},
{obj:Object3, val:100},
{obj:Object4, val:100},
{obj:Object5, val:50}];
delay = 5000;
repeat = objects.length;
t = new Timer(delay, repeat);
t.addEventListener(TimerEvent.TIMER, addRandomObjects, false, 0, true);
t.start();
}
private function addRandomObjects(e:TimerEvent):void
{
var len:int = objects.length;
var rand:int = Math.floor(Math.random() * len);
trace(rand, objects.length);
newObject = new objects[rand].obj();
newObject.amountPointsWorth = objects[rand].val;
newObject.x = Math.random() * (stage.stageWidth- newObject.width);
newObject.y = Math.random() * (stage.stageHeight - newObject.height);
addChild(newObject);
objects.splice(rand, 1);
}
}
}