Skip to main content
July 30, 2007
Question

Actionscript Help Needed

  • July 30, 2007
  • 1 reply
  • 193 views
Hello-To start off im making a game banner in which there is a crying baby and in order to make him happy you need to feed him (excited yet?). Above his head there are randomly rotating food items which you can ciick on to feed the baby and depending on what you feed him the "happiness meter" will go up or down. Now i currently have the right script which generates random food items from an array via the attachMovie function and when you click on the food item it performs the "feeding" animation. My dillema comes in getting the script to distinguish between foods that add to the happines meter and foods that detract from it. Just cant seem to figure out a way to get the script to tag a food "bad" or "good". I have pasted my script below. Any help would be much appreciated, I really need this, its for my job!

stop();

import mx.transitions.Tween;
import mx.transitions.easing.*;

var happiness:Number = 0;
//var foodCount:Number=0;
//var maxHappy:Number = 5;

var getNextFood:Number;


function randomRange(min, max) {
var multiplier:Number = max-min+1;
return Math.floor(Math.random()*multiplier+min);
}

food_arr = new Array("pizza", "cauli", "shroom", "burger", "eggplant", "cookie", "radish");

function getFood() {
var foodMC:MovieClip = _root.attachMovie(food_arr[randomRange(0, 6)], "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, 30, 100, .5, true);
foodMC._x = 200;
foodMC._y = 200;
//getFoodINT=setInterval(getFood, 5000);
foodMC.onPress = function() {
//gotoAndPlay(2);
//food_mc.pizza_mc.gotoAndPlay(2);
ChangeY = new Tween(foodMC, "_y", Regular.easeOut, 200, 350, .5, true);
alphaChangeReverse = new Tween(foodMC, "_alpha", Strong.easeOut, 100, 0, 1, true);
scalex2 = new Tween(foodMC, "_xscale", Bounce.easeOut, 100, 30, .5, true);
scaley2 = new Tween(foodMC, "_yscale", Bounce.easeOut, 100, 30, .5, true);

babyCry_mc.gotoAndPlay(2);
happiness = happiness+20;
happiness_txt.text = happiness+"%";
getNextFood = 20;


};
}


this.onEnterFrame = function() {



if (getNextFood<=0) {
getFood();
getNextFood = 6;// Or however many frames you want to wait
} else {
getNextFood--;
}
trace(happiness);
if (happiness>=100) {
this.babyCry_mc.gotoAndStop(8);
trace("end");
//getFood();
//foodCount++;

}
};
This topic has been closed for replies.

1 reply

kglad
Community Expert
Community Expert
July 30, 2007
you could use a two-d array for your food array. the first element containing the food item linkage id and the 2nd it's health value. when a foodMC is created assign it a value property that matches the food item: