0
votes

Working on an RPG type flash, and I have to be able to control a text-box from quite a few locations. The one that is causing me trouble is the inventory. I need to be able to access the textbox with an instance of "statusWindow" from within the inventory clip (instance name "inventory"), so when I mouse over an item within the movieclip it will change the status window on the stage.

In this instance I want to mouse over inventory.invHealth from the main timeline to get the display. itemName and itemProps are strings containing information about the item.

I tried the following but it gave me a "possibly undefined" error.

    invHealth.addEventListener(MouseEvent.MOUSE_OVER, itemStats);

    function itemStats(e:Event):void
    {
        root.statusWindow.text = itemName+"\n"+itemProps;
    }

I'm not very adept in AS3 just yet, so if you could also explain your code when you post it -though most people usually do anyway- I would very much appreciate it. Thanks in advance!

1

1 Answers

0
votes

I would advice you to store the information data in a class object; that object should be accessible by both the statusWindow and the inventory clip. This way there's no need to "read" a textbox, you will have different views on the same data. For example:

public class GlobalVars
{
    public static var health:Number;
} 

You could of course create a more structured information data, like:

 public class Item
 {
      public function Item(setname:String)
      {
         name=setname;
         health = 100;
         quantity = 0;
      }

      private var name:String;
      private var health:Number;
      private var quantity:Number;
 } 

 var inventory:Array = new Array();
 inventory.push(new Item("hammer"));
 inventory.push(new Item("gun"));
 inventory.push(new Item("sponge"));