so im trying to make a game where your task is to feed a fat baby until he is 100% satisfied
I want the functionality to be that a function calls a random food item from an array really quickly so it’s tough to click on the food he likes. i wrote a function but it crashes my flash and almost my whole mac everytime i run it. Even when i slow the set interval down its still runs really slowly and eventually flash crashes. The food items that are called are all vector items as well so they dont take up alot of filesize. Please help me, i need this for my job! My code is posted below, much thanks to anyone brave enough to help me (some of my old code will be “greyed out”)
stop();
import mx.transitions.Tween;
import mx.transitions.easing.*;
var happiness:Number = 0;
//var foodCount:Number=0;
//var maxHappy:Number = 5;
function randomRange(min, max) {
var multiplier:Number = max-min+1;
return Math.floor(Math.random()*multiplier+min);
}
food_arr = new Array(“pizza”, “cauli”);
function getFood() {
var foodMC:MovieClip = _root.attachMovie(food_arr[randomRange(0, 1)], “food”, this.getNextHighestDepth);
scalex = new Tween(foodMC, “_xscale”, Bounce.easeOut, 0, 100, .5, true);
scaley = new Tween(foodMC, “_yscale”, Bounce.easeOut, 0, 100, .5, true);
alphaChange = new Tween(foodMC, “_alpha”, Strong.easeOut, 0, 100, .5, true);
foodMC._x=200;
foodMC._y=200;
getFoodINT=setInterval(getFood, 5000);
}
for (i=0; i<100; i++){
getFood();
//foodCount++;
foodMC.onPress = function() {
//gotoAndPlay(2);
food_mc.pizza_mc.gotoAndPlay(2);
babyCry_mc.gotoAndPlay(2);
happiness = happiness+20;
happiness_txt.text = happiness+"%";
trace(happiness);
if (happiness>=100) {
//gotoAndStop(45);
trace("end");
}
}
}
/this.food_mc.pizza_mc.onPress = function() {
//gotoAndPlay(2);
food_mc.pizza_mc.gotoAndPlay(2);
babyCry_mc.gotoAndPlay(2);
happiness = happiness+20;
happiness_txt.text = happiness+"%";
trace(happiness);
if (happiness >= 100) {
gotoAndStop (45);
trace(“end”);
}
};
this.food_mc.cauli_mc.onRelease = function() {
//gotoAndPlay(31);
food_mc.cauli_mc.gotoAndPlay(2);
babyCry_mc.gotoAndPlay(27);
happiness = happiness-20;
happiness_txt.text = happiness+"%";
};/