wrote a inventory code
i want to count the item and how many items been left
i have another sence on the fla but from some reason the couting shows only at the first sence
this is the invetory.as
package
{
import flash.display.MovieClip;
import flash.events.MouseEvent;
import flash.media.Sound;
public class InventoryItem extends MovieClip
{
public function InventoryItem()
{
// constructor code
this.buttonMode = true;
this.addEventListener(MouseEvent.CLICK, mouseClickHandler);
}
private function mouseClickHandler(e:MouseEvent):void
{
this.removeEventListener(MouseEvent.CLICK, mouseClickHandler);
this.buttonMode = false;
Main.instance.insertToInventory(this);
var s:Sound = new button4();
s.play();
addBubbles(e.currentTarget);
}
private function addBubbles(e:Object):void
{
var xx:Number = e.x;
var yy:Number = e.y;
var bubble:ballg = new ballg();
bubble.x = xx;
bubble.y = yy;
e.parent.addChild(bubble);
bubble.gotoAndPlay(1);
}
}
}
and this is the main.as
package
{
import flash.display.MovieClip;
import flash.display.DisplayObject;
import flash.text.TextFieldAutoSize;
import com.greensock.TweenMax;
public class Main extends MovieClip
{
public static var instance:Main;
public var totalInventoryItems:Number;
public var collected:Number;
public var remaining:Number;
public var inventory:Array;
public function Main()
{
// constructor code
Main.instance = this;
collected = 0;
msg.txt.text = "";
stop();
}
public function prepareStage()
{
inventory = new Array();
totalInventoryItems = 0;
for (var i:int = 0; i < this.numChildren; i++)
{
if (this.getChildAt(i) is InventoryItem)
{
totalInventoryItems++;
}
}
trace("totalInventoryItems", totalInventoryItems);
}
public function insertToInventory(object:DisplayObject)
{
var xx:Number = (68 - object.width)/2;
if (inventory.length > 0)
{
TweenMax.to(object, 1, {x:xx, y:inventory[inventory.length - 1].y + inventory[inventory.length - 1].height + 10});
}
else
{
TweenMax.to(object, 1, {x:xx, y:10});
}
inventory.push(object);
if (inventory.length == totalInventoryItems)
{
this.nextFrame();
prepareStage();
}
collected++;
remaining = totalInventoryItems - collected;
msg.txt.text = "You still have " + String(remaining) + " objects to collect.";
if(remaining <= 1)
{
msg.txt.text = "You still have " + String(remaining) + " object to collect.";
}
if(remaining <= 0)
{
msg.txt.text = "";
}
}
}
}
what can be the reson its doesnt work on the next scene i have, the item i collcet are have the base class as invetoryitem as well
thank you very much
Sharon