hey guys,
I recently posted requesting some code to generate random food pieces onto the stage etc … I got told to make the pieces of food to fall down and for more than one piece of food to fall down I’d need an onEnterFrame function and setInterval, thing is that I’ve been trying that for AGES and I can’t seem to figure it out.
var goodItems:Array = ["onion", "cheese", "bread", "tomato", "lettuce", "mayo", "pickle"];
var badItems:Array = ["moldyCheese", "moldyBread", "motorOil", "ratPoison"];
// now, whenever you want to drop a new item, we'll create a pointer Array that can point to either our bad items or our good items
var itemPool:Array;
if ( Math.random() * 0.20 )
{
itemPool = badItems;
}
else
{
itemPool = goodItems;
}
// now we know which array to use...let's get a random item in that array.
var arrayIndexToUse:Number = Math.floor(Math.random() * itemPool.length);
var itemToUse:String = itemPool[arrayIndexToUse];
trace( "we are going to spawn in " + itemToUse );
// now attach the movieclip - get the next highest unused depth first so we don't accidentally delete anything
var depth:Number = _root.getNextHighestDepth();
var item:MovieClip = _root.attachMovie(itemToUse, "item_" + depth, depth);
// now position our item randomly across the stage.
item._x = Math.random() * Stage.width;
item._y = 0 - item._height; // this should put the item at the top of the screen.
Here’s the code for attaching and random.
I tried this;
item.onLoad = function () {
speed = 10;
}
item.onEnterFrame = function () {
item._y -=speed;
}
But it doesn’t work, I’m stuck in the ‘onClipEvent’ mindframe so I’m finding it quite difficult.
Could someone please help?