13 Replies Latest reply on Aug 19, 2009 9:56 AM by prodigalmaster

    How do I attach a movieclip from the library so that it sticks to another movieclip. Inventory.

    prodigalmaster Level 2

      Im trying to create an inventory where when you click an object it will automaticly go into your inventory, the inventory is embedded in other movieclips.

      I have quite a few spaces(movieclips) in the inventory box when it is open but I just need it so when you click an object it attaches to a movieclip in the inventory.

      I also need it so that if you click a different item it attaches to the next space in the inventory rather than overlapping an item you have clicked before.

      Also! I would only have only about 15 (or something similar) spaces so if I have clicked 16 items the 16th item cannot go into the inventory.

       

      It seems pretty difficult for me so I may have to just majorly simplify it, if you can think of an easier way then please say.

       

      Thanks.

        • 1. Re: How do I attach a movieclip from the library so that it sticks to another movieclip. Inventory.
          Ned Murphy Adobe Community Professional & MVP

          To attach a movieclip from the library to a movieclip, you use the MovieClip.attachMovie() method--and you have to assign linkage ID's to the symbols in the library (right click -> linkage).  In your case, the MovieClip would be the inventory movieclip, and as far as the attachMovie method goes, the Flash documentation indicates all the arguments that you can specify, and the example code shows how you can also specify where to locate the object.

           

          In your case, the inventory movieclip could have variables that you use to keep count of what's in it which could be handy for limiting the number of items allowed in as well as naming, locating things.

          1 person found this helpful
          • 2. Re: How do I attach a movieclip from the library so that it sticks to another movieclip. Inventory.
            prodigalmaster Level 2

            Ok thanks, il try and get it to work then, il come back later when I mess it up.

            • 3. Re: How do I attach a movieclip from the library so that it sticks to another movieclip. Inventory.
              prodigalmaster Level 2

              OK, so if I go into the inventory space MC and put this code into the frame:

               

              this.attachMovie("fish1_mc","ISpace1",this.getNextHighestDepth());

               

              (im confused about the second argument: newName )

               

              It attaches the right movieclip in the right place, BUT: I would have to make loads of different movieclips(12 altogether) for each different space... thats fine I can do that but the code only works if it is on that frame inside the inventory space MovieClip and...but I need it so when I click a button it attaches the fish mc (item) to a space(mc) in the inventory.

               

              [ Basicly I have an object on the stage (button inside of a movieclip) and I need it so when you click the object it executes the code above but so that the movieclip in the library attaches to the space (which is embedded thoroughly inside menu's and inventory movieclips and buttons.) hich it doesnt.

               

              I hope ive made sense.

               

              Thanks for the help.

              • 4. Re: How do I attach a movieclip from the library so that it sticks to another movieclip. Inventory.
                Ned Murphy Adobe Community Professional & MVP

                Spend some time studying this... I won't be solving your problem for you, but I'll offer what help I reasonably can.

                 

                It's not really clear what you have set up or where what is that is going to put what where--say that 10 time fast.  But here's the thing... you give things instance names and you target them thru the chain of timeline hierarchy.  So let's say you have a buttons for adding different things somewhere.  You can make those buttons call a function either in the inventory movieclip or on the main timeline that will accept an argument indicating which object is to be added.

                 

                Let's say the function is on the main timeline...

                 

                function addObjectToInventory(thisID){

                     // "inventory" is the mc instance name for this example

                     inventory.attachMovie(thisID, "ISpace"+inventory.itemCount, inventory.getNextHighestDepth());

                 

                     // use the itemCount to locate things... someValue? is something you figure out for spacing them

                     inventory["ISpace"+inventory.itemCount]._x = someValue? * inventory.itemCount;

                 

                     // increment the number of items in inventory

                     inventory.itemCount += 1;

                }

                 

                Then whatever timeline(s) you happen to have those buttons in...

                 

                fishBtn.onRelease = function(){

                     _root.addObjectToInventory("fish1_mc");

                }

                 

                If the function instead happens to be inside the inventory mc on its timeline, then the function would use "this" instead of "inventory", and the button function would target:   _root.inventory.addObjectToInventory("fish1_mc");

                 

                As far as the newName thing goes, that is the instance name that you assign to the item you are attaching.  In my example I use the inventory's itemCount variable I invented to make each attached item have a unique name.  And in the line where I define the _x placement of the attached item, you can see how I use the bracket notation to use that same instance name to set _x.

                1 person found this helpful
                • 5. Re: How do I attach a movieclip from the library so that it sticks to another movieclip. Inventory.
                  prodigalmaster Level 2

                  OK, il keep trying on understand your reply.

                   

                  That toungue twister thyself thought of twisted my tongue ten times!

                  lol

                   

                  Anyway by the way, just to un-confuse you:

                   

                  On the (_root) main timeline I have a symbol which is a MC: object_fish1_mc

                  when you go into that MC it(there) is a button symbol.

                   

                  When I click (at runtime) the button of the fish (which is inside of the object_fish1_mc MC) I need it so it attaches the movieclip of the fish (object_fish1_mc with the linkage of: fish1_mc), to one space on the inventory.

                   

                  The inventory:

                  I have a MC: UI1_mc (sub menu)

                  inside of it many other buttons and MCs (settings like quality and sound volume)

                  inside of a 'Graphic' symbol (from a tween) is an MC: UI_inv_mc

                  inside of that is many frames of different animation and 'stuff' (animating the inventory box to appear etc when you click the inventory button)

                  At a perticular frame (fr. 10) is the box for the inventory containing 12 MCs : Instances of: Inv_space_mc (12 spaces for items)

                  They are the spaces where the fish attaches to when you click the fish.

                  One of the spaces (the first one) has an instance name of: ISpace1

                   

                  I hope I have cleared any confusion that you showed at the start of your reply.

                   

                  Right! im gonna try and get it working.... omfg its late.. early (1 am)

                   

                  uuuh goodnight il come back in the morning maybe, il see if I can get the function working or whatever.

                  goodnighhtt..

                  • 6. Re: How do I attach a movieclip from the library so that it sticks to another movieclip. Inventory.
                    prodigalmaster Level 2

                    Goodmorning, ive been working on it and ive decided to do it differently, the new way is much easier for me.

                     

                    On the main timeline you click the fish and a box appears asking if you want to put it in your inventory, then if you click yes the inventory box opens (from root it is: _root.UI1_mc.UI1_mc2.inv_mc.gotoAndStop(10); )

                    It works, the inventory box opens. But its in the wrong place although im working on it.

                     

                    I then make the fish draggable so you can drag it then hover it over a space in the inventory and maybe using hitTest or something get it to attach.

                    I hope it will stay attached so it is still there when I close then reopen the inventory.

                    • 7. Re: How do I attach a movieclip from the library so that it sticks to another movieclip. Inventory.
                      prodigalmaster Level 2

                      OK, so I have most of it working now, I can drag the fish_mc into the inventory and it attaches a different mc that looks exactly the same from the library onto the ISpace1 and it puts the invCount up by one and the draggable fish_mc disappears (_visible = false) .

                       

                      But when I reopen the inventory it is not there.

                       

                      I may work out soon actually so goodbye.

                      • 8. Re: How do I attach a movieclip from the library so that it sticks to another movieclip. Inventory.
                        Ned Murphy Adobe Community Professional & MVP

                        If you have to navigate to a frame to see the inventory, then anything you add to it will not stick.    You either have to have the inventory always present or you have to store information about what is in the inventory (information that is always present) so that it can be added dynamically every time you access the inventory.  In any case, something has to always be present that maintains the inventory... either the inventory itself or data that defines what's in it.

                        • 9. Re: How do I attach a movieclip from the library so that it sticks to another movieclip. Inventory.
                          prodigalmaster Level 2

                          OK, il have it so the inventory is off screen but when you click the 'inventory open button' it just scrolls up to where you can see it?

                           

                          il work it out somehow.

                          • 10. Re: How do I attach a movieclip from the library so that it sticks to another movieclip. Inventory.
                            Ned Murphy Adobe Community Professional & MVP

                            That would be one way, or you could control the inventory mc _visible property instead

                            • 11. Re: How do I attach a movieclip from the library so that it sticks to another movieclip. Inventory.
                              prodigalmaster Level 2

                              All of the inventory box is called: inventory_mc

                              It is on a new layer inside a load of mc's and it is always there but I have put:

                              onClipEvent (enterFrame) {
                                  this._visible = false();
                              }

                              on the MC to get it to go invisible... its not.

                              why?

                               

                              I also tried:

                              inventory_mc._visible = false();

                              on the frame but it didnt work.

                               

                               

                               

                              do you know why _visible isnt working, should I just use up the CPU with the actionscript alpha property thingy?

                               

                              _alpha = 0; works fine.

                               

                              but doesnt it use too much computing power or something?

                              • 12. Re: How do I attach a movieclip from the library so that it sticks to another movieclip. Inventory.
                                Ned Murphy Adobe Community Professional & MVP

                                false is not a function, it is a value.... _visible = false;

                                • 13. Re: How do I attach a movieclip from the library so that it sticks to another movieclip. Inventory.
                                  prodigalmaster Level 2

                                  oops. OK thanks.

                                   

                                  I use _alpha anyway because _visible = false; shows the instance for a split second but you dont see it at all with _alpha = 0;