I am trying to get certain XML attributes from my XML file into a text box. These attributes are w, d. When I click on an item in the scrollPane thumbs, I want the w and d of that item to appear in the text boxs item_h.text, and item_w.text. Now I set up a global variable for each which might not be the best way. If the Bedroom items are in the scrollPane, I can only get the last items w,d to appear regardless of what I click on.
Can someone help me figure out how to do this?
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<menu name="Library">
<menu Text="BedRoom">
<item name="Bed" ItemSWF="bed" w="65" d="84" />
<item name="Bunk bed" ItemSWF="bunkBed" w="43" d="81" />
</menu >
<menu Text="Chairs">
<item name="Recliner" ItemSWF="chair" w="40" d="35" />
</menu >
<menu Text="Sofas">
<item name="Leather Sofa" ItemSWF="sofa" w="85" d="37" />
</menu >
</menu >
var myXML:XML = new XML();
myXML.ignoreWhite = true;
libraryList_ar = new Array();
combo_list.dataProvider = libraryList_ar;
myXML.onLoad = function(success) {
if (success) {
//trace(this);
var libraries = this.firstChild;
var dValue = this.firstChild.attributes.name;
//trace(dValue);
combo_list.textField.label.text = "Library";
var libCount = libraries.childNodes.length;
//trace(libCount);
var libItems = libraries.firstChild.childNodes.length;
//trace(libItems);
for (var i = 0; i<libCount; i++) {
libraryList_ar* = new Object();
libraryList_ar*.label = libraries.childNodes*.attributes.Text;
libraryList_ar*.data = libraries.childNodes*;
//save reference here
}
}
};
myXML.load("itemMenu.xml");
//
combo_list.change = function(eventObj) {
thumbs.invalidate();
thumbs.refreshPane();
var selItem:Object = eventObj.target.selectedItem;
var itemXML:XMLNode = selItem.data;
for (var i = 0; i<itemXML.childNodes.length; i++) {
var t_mc:MovieClip;
t_mc = thumbs.content.attachMovie("thumb_mc", "thumb"+i, i, this.getNextHighestDepth());
t_mc._x = 5;
t_mc._y = 5+(i*80);
_root["mc"+i] = new MovieClipLoader();
_root["mc"+i].addListener(mclListener);
_root["mc"+i].loadClip("decals/"+itemXML.childNodes*.attributes.ItemSWF+".swf", t_mc.Container_mc);
t_mc.i = i;
t_mc.piece = itemXML.childNodes*.attributes.ItemSWF;
//save reference here
// get width and depth dimensions of item
_global.j = itemXML.childNodes*.attributes.w;
_global.k = itemXML.childNodes*.attributes.d;
// assign on release function
t_mc.onRelease = newPiece;
}
};
combo_list.addEventListener("change", combo_list);
//
_global.count = 0;
function newPiece() {
// create a movieclip to hold the functionality of the peice of furniture
// keep all the furniture inside 1 clip (called 'pieceContainer') for organizational purposes
// var count:Number = floor.pieceContainer.getNextHighestDepth();
var item_mc:MovieClip = pieceContainer.createEmptyMovieClip("item_mc"+count, this.getNextHighestDepth());
//trace(count);
count++;
// create a container to load the furniture swf into
var container:MovieClip = item_mc.createEmptyMovieClip("container_mc", 0);
container._x = 0;
container._y = 0;
// setup a MCL to handle the swf's loading, when its loaded, apply the freeTransform methods to it.
item_mc.mcl = new MovieClipLoader();
item_mc.mcl.addListener(mclListener_2);
item_mc.mcl.loadClip("decals/"+this.piece+".swf", container);
//add value of width and depth to text box
item_w.text = j;
item_h.text = k;
}
//
var mclListener_2:Object = new Object();
mclListener_2.onLoadInit = function(mc:MovieClip) {
// set variables to remember the original dimensions
var axw = mc._width;
var axh = mc._height;
//
trace(pieceContainer._width);
trace(pieceContainer._height);
// center piece
mc._y = -(axh/2);
mc._x = -(axw/2);
//
//addFreeTransform
mc._parent.onPress = function() {
this.addFreeTransform();
};
};