I have an issue, I have about 25 mc’s that are named carBtn1 through carBtn25 - the problem is when I index my array - its only taking the first number from the end of the carBtn, so carBtn1 is seen as the same as carBtn10. I tried taking the last 2 digits off which works for 2 digit numbers - but everything below 10 isnt working anymore. Im not sure what to do to get it working…
Here is my code:
// variables
var popInfo:popMc;
// load xml
var xml:XML = new XML();
var loader:URLLoader = new URLLoader();
loader.load(new URLRequest("data/cities.xml"));
loader.addEventListener(Event.COMPLETE,
function(evt:Event):void {
xml = XML(evt.target.data);
//trace(xml.city[0][email protected]());
var url:URLRequest = new URLRequest(xml.city[0][email protected]());
}
);
// event listeners
stage.addEventListener(MouseEvent.CLICK, onClickStageRemove);
for (var j:int = 0; j < 11; j++)
{
getChildByName("carBtn" + j).addEventListener(MouseEvent.CLICK, onClickLoadData);
getChildByName("carBtn" + j).addEventListener(MouseEvent.MOUSE_OVER, onCarHover);
getChildByName("carBtn" + j).addEventListener(MouseEvent.MOUSE_OUT, onCarOut);
}
// button mode
buttonMode = true;
// functions
function onCarHover(event:MouseEvent):void
{
event.target.gotoAndPlay(11);
}
function onCarOut(event:MouseEvent):void
{
event.target.gotoAndPlay(10);
}
function onClickLoadData(event:MouseEvent):void
{
popInfo = new popMc();
popInfo.x = 100;
popInfo.y = 50;
addChild(popInfo);
popInfo.closeBtn.addEventListener(MouseEvent.CLICK , onClickRemove);
popInfo.nyopBtn.addEventListener(MouseEvent.CLICK, onClickNYOP);
//better approach would be add separate classFile to haldle some popInfo's events
//such removing on stageClick in that file u could add those functions:
var index:Number=event.target.name.slice(event.target.name.length-1);
popInfo.carsizeText.text = xml.city[index].bidlist.carsize.descendants().toXMLString();
popInfo.priceText.text = xml.city[index].bidlist.price.descendants().toXMLString();
popInfo.savingsText.text = xml.city[index].bidlist.savings.descendants().toXMLString();
popInfo.stateText.text = xml.city[index][email protected]();
addChild(popInfo);
}
function onClickRemove(event:MouseEvent):void
{
popInfo.closeBtn.removeEventListener(MouseEvent.CLICK, onClickRemove);
popInfo.nyopBtn.removeEventListener(MouseEvent.CLICK, onClickNYOP);
removeChild(popInfo);
}
function onClickStageRemove(event:MouseEvent):void
{
if(event.eventPhase == EventPhase.AT_TARGET) {
removeChild(popInfo);
}
}
function onClickNYOP(event:MouseEvent):void
{
//navigateToURL(url, "_blank");
// navigateToURL(urlNY, "_blank"); //trying to get this variable to work
ExternalInterface.call("selectNY");
}
// set button mode here