3 Replies Latest reply on Mar 5, 2010 4:41 PM by Rothrock

    Eval() Problem


      I'm trying to make an inventory.


      I have a slot, thats a movieclip, under the inventory.. So there at _root.Inventory.ItemSlot


              item._x = eval("ItemSlot" + currentslotnum)._x;
              item._y = eval("ItemSlot" + currentslotnum)._y;


      How can I make it so it knows the exact spot they are located at? Cause there at Inventory.ItemSlot not just ItemSlot.

        • 1. Re: Eval() Problem
          Rothrock Level 5

          Yeah don't use eval it is difficult to use and is depreciated. Use array notation:




          Also it is better to do this once than multiple times.


          var curSlot:MovieClip=inventory["itemSlot"+currentSlotNum]





          Easier to read. Less prone to typos. Actually faster to process. Wins all around.


          This all is assuming that inventory instance is within the scope of the current timeline. (Which I'm guessing from your code that it won't be....)


          Here are a couple of tips. Use lowercase for the first letter of instance names. Upper case is usually only used for Class names.

          • 2. Re: Eval() Problem
            TheBrody Level 1

            I did that but...


            it moves item1 to -40, -60 on the stage, it doesnt move it to -40, -60 inside the actual inventory movie clip.

            • 3. Re: Eval() Problem
              Rothrock Level 5

              Not sure what you mean by that. But if item is on the main timeline and inventory.itemSlot1 is at -40 inside inventory, then it is doing what you have asked it to do.


              If you want them to be in the same locations you could do:




              Or if you have very contorted design you could look into using the globalToLocal or localToGlobal to handle the transforms.


              After years of doing this kind of stuff I generally design stuff to begin with in a manner that makes the positioning easier. It is hard to describe exactly how I do it....