• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Inventory

New Here ,
Jul 16, 2012 Jul 16, 2012

Copy link to clipboard

Copied

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?

TOPICS
ActionScript

Views

1.5K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Jul 17, 2012 Jul 17, 2012

Copy link to clipboard

Copied

Please explain it clearly...

You want to transfer items automatically or manually?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Jul 18, 2012 Jul 18, 2012

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 19, 2012 Jul 19, 2012

Copy link to clipboard

Copied

Thank you, id like to transfer the items via pick-up / drop, and also if you can explane me what means " this" and how transfer movieclips between stage and library

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Jul 19, 2012 Jul 19, 2012

Copy link to clipboard

Copied

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

^ 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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 19, 2012 Jul 19, 2012

Copy link to clipboard

Copied

Thank you, but about the B problem i meant this: this[target_inv][target_slot];


and i likened target_inv with x and target_slot with y for alla the occations. Nm what does it mean?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Jul 20, 2012 Jul 20, 2012

Copy link to clipboard

Copied

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 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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 21, 2012 Jul 21, 2012

Copy link to clipboard

Copied

Thank you again but i still dont understand these lines:

     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;

Could you explane them?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Jul 21, 2012 Jul 21, 2012

Copy link to clipboard

Copied

LATEST

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines