I know there must be an easier way to write this code using loops/arrays, but I can seem to get it working with AS3. I have been writing in AS3 for under 3 days, I just made the switch from AS2.0. Can someone help me! I would consider paying someone to explain it to me over the phone!
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].@weburl.toString());
var url:URLRequest = new URLRequest(xml.city[0].@weburl.toString());
}
);
// event listeners
stage.addEventListener(MouseEvent.CLICK, onClickStageRemove);
carBtn0.addEventListener(MouseEvent.CLICK, onClickLoadData);
carBtn0.addEventListener(MouseEvent.MOUSE_OVER, onCarHover);
carBtn0.addEventListener(MouseEvent.MOUSE_OUT, onCarOut);
carBtn1.addEventListener(MouseEvent.CLICK, onClickLoadData);
carBtn1.addEventListener(MouseEvent.MOUSE_OVER, onCarHover);
carBtn1.addEventListener(MouseEvent.MOUSE_OUT, onCarOut);
carBtn2.addEventListener(MouseEvent.CLICK, onClickLoadData);
carBtn2.addEventListener(MouseEvent.MOUSE_OVER, onCarHover);
carBtn2.addEventListener(MouseEvent.MOUSE_OUT, onCarOut);
carBtn3.addEventListener(MouseEvent.CLICK, onClickLoadData);
carBtn3.addEventListener(MouseEvent.MOUSE_OVER, onCarHover);
carBtn3.addEventListener(MouseEvent.MOUSE_OUT, onCarOut);
carBtn0.buttonMode = true;
carBtn1.buttonMode = true;
carBtn2.buttonMode = true;
carBtn3.buttonMode = true;
// functions
function onCarHover(event:MouseEvent):void
{
if(event.target == carBtn0)
{
carBtn0.gotoAndPlay(10);
}
else if(event.target == carBtn1)
{
carBtn1.gotoAndPlay(10);
}
else if(event.target == carBtn2)
{
carBtn2.gotoAndPlay(10);
}
else if(event.target == carBtn3)
{
carBtn3.gotoAndPlay(10);
}
}
function onCarOut(event:MouseEvent):void
{
if(event.target == carBtn0)
{
carBtn0.gotoAndPlay(9);
}
else if(event.target == carBtn1)
{
carBtn1.gotoAndPlay(9);
}
else if(event.target == carBtn2)
{
carBtn2.gotoAndPlay(9);
}
else if(event.target == carBtn3)
{
carBtn3.gotoAndPlay(9);
}
}
function onClickLoadData(event:MouseEvent):void
{
if(event.target == carBtn0)
{
popInfo = new popMc();
popInfo.x = 100;
popInfo.y = 50;
addChild(popInfo);
popInfo.closeBtn.addEventListener(MouseEvent.CLICK , onClickRemove);
popInfo.nyopBtn.addEventListener(MouseEvent.CLICK, onClickNYOP);
popInfo.carsizeText.text = xml.city[0].bidlist.carsize.descendants().toXMLString();
popInfo.priceText.text = xml.city[0].bidlist.price.descendants().toXMLString();
popInfo.savingsText.text = xml.city[0].bidlist.savings.descendants().toXMLString();
popInfo.stateText.text = xml.city[0].@name.toString();
}
else if(event.target == carBtn1)
{
popInfo = new popMc();
popInfo.x = 130;
popInfo.y = 50;
addChild(popInfo);
popInfo.closeBtn.addEventListener(MouseEvent.CLICK , onClickRemove);
popInfo.nyopBtn.addEventListener(MouseEvent.CLICK, onClickNYOP);
popInfo.carsizeText.text = xml.city[1].bidlist.carsize.descendants().toXMLString();
popInfo.priceText.text = xml.city[1].bidlist.price.descendants().toXMLString();
popInfo.savingsText.text = xml.city[1].bidlist.savings.descendants().toXMLString();
popInfo.stateText.text = xml.city[1].@name.toString();
}
else if(event.target == carBtn2)
{
popInfo = new popMc();
popInfo.x = 100;
popInfo.y = 50;
addChild(popInfo);
popInfo.closeBtn.addEventListener(MouseEvent.CLICK , onClickRemove);
popInfo.nyopBtn.addEventListener(MouseEvent.CLICK, onClickNYOP);
popInfo.carsizeText.text = xml.city[2].bidlist.carsize.descendants().toXMLString();
popInfo.priceText.text = xml.city[2].bidlist.price.descendants().toXMLString();
popInfo.savingsText.text = xml.city[2].bidlist.savings.descendants().toXMLString();
popInfo.stateText.text = xml.city[2].@name.toString();
}
else if(event.target == carBtn3)
{
popInfo = new popMc();
popInfo.x = 100;
popInfo.y = 50;
addChild(popInfo);
popInfo.closeBtn.addEventListener(MouseEvent.CLICK , onClickRemove);
popInfo.nyopBtn.addEventListener(MouseEvent.CLICK, onClickNYOP);
popInfo.carsizeText.text = xml.city[3].bidlist.carsize.descendants().toXMLString();
popInfo.priceText.text = xml.city[3].bidlist.price.descendants().toXMLString();
popInfo.savingsText.text = xml.city[3].bidlist.savings.descendants().toXMLString();
popInfo.stateText.text = xml.city[3].@name.toString();
}
}
function onClickRemove(event:MouseEvent):void
{
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