Is it possible to reference an object using a variable value?
For example, I have a function that is supposed to hide an image and add that image to an inventory list when the item is clicked.
All the image info is stored in an object (name, imgSource, visible, x, y);
I was thinking I could do something like this:
<fx:Script>
<![CDATA[
public var item:Object = new Object();
// name, imgSource, xPos, yPos, visible
[Bindable]
public var knife:ItemInfo = new ItemInfo('knife','knife.png',50,50,true);
public function addItem(evnt:MouseEvent):void
{
// I want "item" to be equal to the object "knife"
item = evnt.currentTarget.name;
item.visible = false;
inventory.addItem(item.name);
}
]]>
</fx:Script>
<s:Image source="{knife.source}" name="knife"
x="{knife.xPos}" y="{knife.yPos}"
visible="{knife.visible}"
click="addItem(event);" />
I want "item" to stand for knife so that I could change knife.visible, knife.xPos, ect.
Is that possible, or is there a better way to do this?
Thanks!