Skip navigation
Currently Being Moderated

Inventory

Jul 16, 2012 12:55 AM

Hey guy, i want to make a game inventory and here is the file:

 

https://hotfile.com/dl/163389724/dc84168/inventory.fla.html

 

Lets say that the 2 big green rectangles are the inventories bg images, the small red are the empty item slots and the blue one is an item. I want the player to be able to transfer items from the one inventroy to another, can you help me?

 
Replies
  • Currently Being Moderated
    Jul 17, 2012 5:23 AM   in reply to Pettas

    Please explain it clearly...

     

    You want to transfer items automatically or manually?

     
    |
    Mark as:
  • Currently Being Moderated
    Jul 18, 2012 8:27 PM   in reply to Pettas

    Well, you can always set up the inventories as 2 separate arrays:

     

    Ex.

     

    var inv1:Array = new Array(); //inventory 1

    var inv2:Array = new Array(); //inventory 2

     

    Then each array element would be a slot, and each item would be defined as a string.

     

    Ex.

     

    inv1 = ["open slot", "open slot", "money"];

    inv2 = ["open slot', open slot", "open slot"];

     

    Then a function of this sort would swap an item to the first open slot:

     

    function swap(target_inv:String, target_slot:int, destination_inv:String, destination_slot:int):void

    {

         var item1:String = this[target_inv][target_slot];

         var item2:String = this[destination_inv][destination_slot];

         this[target_inv][target_slot] = item2;

         this[destination_inv][destination_slot] = item1;

    }

     

    I would also make the items MovieClips, remove them from the stage, then link them for actionscript in the library; that way, you can attach the movieclips to a movieclip holder, then destroy them and re-add them whenever a swap is made.

     
    |
    Mark as:
  • Currently Being Moderated
    Jul 19, 2012 6:40 PM   in reply to Pettas

    A. Transfering movieclips from library to stage.

     

    *Note: Even when a MovieClip is deleted from the stage, it still exists until it is actually deleted from the library.

     

    1. Go to the Library Panel, find the MovieClip you want > right click  > properties > check export for actionscript > give it a class name where it says "class".  This will allow you to access that movieclip from the library using the name you give it.

     

    2. You can simply add this so the stage by writing:

     

    var o:your_class_name = new your_class_name();

    o.name = some_name;

    o.x = some_x_position;

    o.y = some_y_position;

    some_mc_holder.addChild(o);

     

    some_name is a name you can access that specific instance by from the stage later on by using: some_mc_holder.getChildByName(some_name);

     

    3. However, your items will be given different class names, so you'll want to add MovieClips with a varying class name.  To do this we will define a Class variable:

     

    var c:Object = getDefinitionByName(your_class_name as a string);

    var o:MovieClip = new c();

    o.name = some_name;

    o.x = some_x_position;

    o.y = some_y_position;

    some_mc_holder.addChild(o);

     

    B. this[x][y]

     

    ^ this makes absolutely no sense, and has no use what so ever.

     

    C. Drag and Drop

     

    *Note: this is actually quite difficult and tedious to program.

     

    1. use the variables: mouseX and mouseY to get the position of the mouse.

     

    2. use the event MouseEvent.MOUSE_DOWN and MouseEvent.MOUSE_UP to listen for when the mouse is being held.  During this time, assign the x and y coordinates of a target object to that of the mouse.  This takes a while to do right.

     
    |
    Mark as:
  • Currently Being Moderated
    Jul 20, 2012 10:55 AM   in reply to Pettas

    object1.object2

    object1["object2"]

     

    ^these mean the same thing, the brackets just allow you to define an object on another object dynamically.

     

    The reason this[x][y] makes no sense is because "this" is an object, and "x" and "y" are coordinated of "this"; so... if this.x = 5 and this.y = 3, then you are essentially writing this.5.3, and variables cannot be defined by an integer alone.  The only way this would be possible is if "this" was an array, but then it wouldnt have an "x" and "y" property.

     
    |
    Mark as:
  • Currently Being Moderated
    Jul 21, 2012 12:44 AM   in reply to Pettas

    this[target_inv] is an array that holds the items for the selected inventory and target_slot is the index (or item) referenced.

     

    Ex:

     

    target_inv = "inv1";

    target_slot = 1;

     

    so

    this[target_inv][target_slot]

    is the same as

    this.inv1[1]

    which is also the same as

    inv1[1]

     

    same thing for the destination.

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points