Is there any way to pass a variable when calling the onRelease() function? In the example below, I am dynamically creating a series of rows/buttons and would like to dynamically load additional text from an array when clicking the row/button.
The problem is...the value for "i" is not being stored when the button behavior is defined. In the case below, "i" always has a value of "4" -- which traces undefined. I need "i" to be stored as "0", "1", "2", etc. when I define the button behavior.
Any help would be greatly appreciated...including a different way of doing it
Code:
//Loads easing
var easeType = mx.transitions.easing.Strong.easeOut;
//Expands view
contentHolder.showRows.onRelease = function(){
myTween = new mx.transitions.Tween(contentHolder, "_X", easeType, -445, 35, 10);
}
//Dummy data for testing
var myARR = new Array(
{city:"New York", description:"MTA raises subway fares", date:"2005", contentT:"Blah, blah, blah"},
{city:"Los Angeles", description:"Traffic continues to be a problem", date:"2004", contentT:"Blah, blah, blah"},
{city:"London", description:"Will the rain ever stop?", date:"2005", contentT:"Blah, blah, blah"},
{city:"Paris", description:"Top 10 things to do", date:"2003", contentT:"Blah, blah, blah"}
);
//Vertical starting position for the first button
vertPosition=0;
//Dynamically create rows of buttons.
for (var i = 0; i < myARR.length; i++) {
contentHolder.scrollWindow.spContentHolder.attachMovie("singleRow", "singleRow"+i+"_mc", contentHolder.scrollWindow.spContentHolder.getNextHighestDepth(), {_x:0, _y:vertPosition});
contentHolder.scrollWindow.spContentHolder["singleRow"+i+"_mc"].cityText = myARR[i].city;
contentHolder.scrollWindow.spContentHolder["singleRow"+i+"_mc"].descriptionText = myARR[i].description;
contentHolder.scrollWindow.spContentHolder["singleRow"+i+"_mc"].dateText = myARR[i].date;
//Assign actions to each button
contentHolder.scrollWindow.spContentHolder["singleRow"+i+"_mc"].rowButton.onRelease = function(){
//PROBLEM HERE -- "i" not being stored. The value of "i" gets looked up when calling the function.
contentHolder.descriptionText2 = myARR[i].description;
contentHolder.contentText = myARR[i].contentT;
myTween = new mx.transitions.Tween(_root.contentHolder, "_X", easeType, 0, -445, 10);
}
vertPosition=vertPosition+24;
}
stop();