Here’s the XML.
<cart>
<color01 name="Mothwing Mountain Mimicry">
<size name="small" price="69.99"></size>
<size name="medium" price="69.99"></size>
<size name="large" price="69.99"></size>
<size name="xl" price="69.99"></size>
<size name="xxl" price="79.99"></size>
<size name="xxxl" price="79.99"></size>
</color01>
<color02 name="Stone">
<size name="small" price="79.99"></size>
<size name="medium" price="79.99"></size>
<size name="large" price="79.99"></size>
<size name="xl" price="79.99"></size>
<size name="xxl" price="89.99"></size>
<size name="xxxl" price="89.99"></size>
</color02>
</cart>
here’s what I’m doing…
First I’m loading the Color names (ie.Mothwing and Stone) into a combo box… using a For Loop.
Here’s where I’m running into problems… I need to load the size, and price into another combo box, based on its parent.
So if you choose the mothwing color the Size combo box changes to the correct available sizes. When you choose a specific size the price then changes to the correlating price.
I need something like this:
info_mc.cartSlider_mc.cartSlider_mc.color.addEventListener("change", colorListener);
colorListener.change = function() {
POPULATE SIZE COMBO BOX WITH CORRECT SIZES BASED ON COLOR SELECTION
};
I can’t figure it out…
please someone mock something up for me
or guide me.
Thanks!!
Richie
So Close I can taste it!!
Using the same XML
var product_xml = new XML();
function loadXML(w) {
product_xml.ignoreWhite = true;
product_xml.load("xml/cart.xml");
product_xml.onLoad = function(success) {
if (success) {
_global.colorArray = new Array();
_global.sizeArray = new Array();
sizeSubArray = new Array();
_global.priceArray = new Array();
priceSubArray = new Array();
//sizeArray = new Array;
trace(product_xml.firstChild.childNodes.length);
trace(product_xml.firstChild.firstChild.childNodes.length);
trace(product_xml.firstChild.childNodes[0].childNodes[0]);
trace("size Length = "+product_xml.firstChild.childNodes[0].childNodes.length);
trace("debug = "+product_xml.firstChild.childNodes[0].childNodes[0].attributes.name);
info_mc.cartSlider_mc.cartSlider_mc.color.addItem({data:null, label:"Please Select a color"});
for (var a = 0; a<product_xml.firstChild.childNodes.length; a++) {
colorArray[a] = product_xml.firstChild.childNodes[a].attributes.color;
info_mc.cartSlider_mc.cartSlider_mc.color.addItem({label:colorArray[a], data:a});
trace("color = "+colorArray[a]);
for (var b = 0; b<product_xml.firstChild.childNodes[a].childNodes.length; b++) {
priceSubArray** = product_xml.firstChild.childNodes[a].childNodes**.attributes.price;
sizeSubArray** = product_xml.firstChild.childNodes[a].childNodes**.attributes.size;
sizeArray[a] = sizeSubArray;
priceArray[a] = priceSubArray;
trace("sizeArray"+"["+a+"]["+b+"] = "+sizeArray[a]**);
trace("priceArray"+"["+a+"]["+b+"] = "+priceArray[a]**);
}
/// TRIAL SCRIPT TO DEFINE PRICE ON CHANGE BASED ON SIZE ///
var colorListener:Object = new Object();
info_mc.cartSlider_mc.cartSlider_mc.color.addEventListener("change",colorListener);
colorListener.change = function() {
trace("selectedData = "+info_mc.cartSlider_mc.cartSlider_mc.color.selectedItem.data);
loadSize_fn(info_mc.cartSlider_mc.cartSlider_mc.color.selectedItem.data);
};
}
} else {
trace("Error loading XML file");
}
};
}
loadXML(0);
function loadSize_fn(c) {
info_mc.cartSlider_mc.cartSlider_mc.size.removeAll();
info_mc.cartSlider_mc.cartSlider_mc.size.addItem({data:null, label:"Please Select size"});
for (d=0; d<sizeArray[c].length; d++) {
trace(sizeArray[c].length);
trace("sizeArray"+"["+c+"]["+d+"] = "+sizeArray[c][d]);
info_mc.cartSlider_mc.cartSlider_mc.size.addItem({label:sizeArray[c][d], data:priceArray[c][d]});
}
}
/// TRIAL SCRIPT TO DEFINE PRICE ON CHANGE BASED ON SIZE ///
var sizeListener:Object = new Object();
info_mc.cartSlider_mc.cartSlider_mc.size.addEventListener("change",sizeListener);
sizeListener.change = function() {
trace("selectedData = "+info_mc.cartSlider_mc.cartSlider_mc.size.selectedItem.data);
trace("priceArray[0][5] ="+priceArray[0][5]);
//loadSize_fn(info_mc.cartSlider_mc.cartSlider_mc.color.selectedItem.data);
info_mc.cartSlider_mc.cartSlider_mc.price_txt.text = info_mc.cartSlider_mc.cartSlider_mc.size.selectedItem.data;
};
My sizeSubArray, and priceSubArray are being overWritten with each cycle… They need to have unique dynamic names… but I’m not sure of the syntax… please please please help…