I’m trying to write a function that keeps a running count whenever a button is clicked - and then writes the count to a Shared Object cookie. Here’s the code:
function counterVar() {
var elemSharedObject:SharedObject = SharedObject.getLocal("elementChoices", "/");
countClicks = elemSharedObject.data.itemCount;
if (elemSharedObject.data.itemCount == 'undefined' || '' || 'NaN') {
elemSharedObject.data.itemCount = 1;
elemSharedObject.flush();
countClicks = 1;
} else {
countClicks++;
elemSharedObject.data.itemCount = countClicks;
elemSharedObject.flush();
}
}
And the button code looks like this:
function click(bt:Object):Void {
if (bt.target == table_mc.p1_bt) {
var elemArray:Array = new Array(_root.p1, _root.i1, _root.e1, _root.en1);
var elemArrayName = "elemArray_" + _root.countClicks;
storeData(elemArrayName,elemArray);
//Alert.show("You've added " + _root.i1 + " to the cart");
counterVar();
} //else if...
}
Everytime it runs the count gets reset to “1”, endlessly. Obviously the logic is flawed. Can anyone help out here?