Inventory From AS3 to HTML5
- September 21, 2019
- 1 reply
- 398 views
Hello dear people. Some one can help me with this html inventory for a simple game?
the code is in AS3 and I want to use it in HTML.
package { import flash.display.*;
public class InventoryDemo extends MovieClip { var inventory:Inventory;
function InventoryDemo() { inventory = new Inventory(this);
inventory.makeInventoryItems([box1,box2,box3,box4]); } } }
and the other part of the code
package { import flash.display.*;
import flash.events.*;
public class Inventory { var itemsInInventory:Array;
var inventorySprite:Sprite;
function Inventory(parentMC:MovieClip) { itemsInInventory = new Array()
; inventorySprite = new Sprite();
inventorySprite.x = 50;
inventorySprite.y = 360;
parentMC.addChild(inventorySprite); }
function makeInventoryItems(arrayOfItems:Array) { for(var i:int=0;i<arrayOfItems.length;i++) { arrayOfItems[i].addEventListener(MouseEvent.CLICK, getItem);
arrayOfItems[i].buttonMode = true; } }
function getItem(e:Event) { var item:MovieClip = MovieClip(e.currentTarget);
itemsInInventory.push(item);
inventorySprite.addChild(item);
item.x = (itemsInInventory.length-1)*40;
item.y = 0;
item.removeEventListener(MouseEvent.CLICK, getItem);
item.addEventListener(MouseEvent.CLICK, useItem); }
function useItem(e:Event) { var item:MovieClip = MovieClip(e.currentTarget);
trace("Use Item: "+item.name); } } }
