So you want to run this part of the top of the code again?
Code:
import mx.utils.Delegate;
//
var rootNode:XMLNode;
var productsNode:Array;
var totalProducts:Number;
var myProducts_xml = new XML();
//
myProducts_xml.ignoreWhite = true;
myProducts_xml.onLoad = Delegate.create(this, getTotalProducts);
myProducts_xml.load("prodData/products.xml"); //local version
//myProducts_xml.load("prodData/products.xml?ran="+random(999999)); //web version (cache killer)

//
Does throwing just that above stuff into a function give you those 'undefined' problems you were talking about?