PDA

View Full Version : Why are my buttons not working?


NCarolina
11-09-2009, 04:14 PM
My XML is being called but my buttons are not working properly so the text fields are not populated. The rollout rollover alpha is not working. Any suggestions? This has got to be so simple.

Here is my script:

stop();
var buttons:Array = [box1_btn, box2_btn, box3_btn];
for (var i = 0; i<buttons.length; i++) {
buttons[i].onRollOut = function() {
this._alpha = 100;
};
buttons[i].onRollOver = function() {
this._alpha = 50;
};
}
var divisionsXML:XML = new XML();
var office:Array = new Array();
var leadership:Array = new Array();
var overview:Array = new Array();
var mission:Array = new Array();
var organization:Array = new Array();

for (var i = 0; i<3; i++) {
buttons[i].id = i;
buttons[i].onRelease = function() {
this._parent.loadOffice(this.id);
};
}
function loadOffice(i) {
officetf.text = office[i];
leadershiptf.text = leadership[i];
overviewtf.text = overview[i];
missiontf.text = mission[i];
organizationtf.text = organization[i];
}

divisionsXML.ignoreWhite = true;
divisionsXML.load("divisions.xml");
divisionsXML.onLoad = divisionsLoad;
function divisionsLoad() {
var divisionsNum:Number = divisionsXML.firstChild.childNodes.length;
for (var i = 0; i<divisionsNum; i++) {
var officeNode:XMLNode = divisionsXML.firstChild.childNodes[i].childNodes[0];
office.push(officeNode.firstChild.nodeValue);
var leadershipNode:XMLNode = divisionsXML.firstChild.childNodes[i].childNodes[1];
leadership.push(leadershipNode.firstChild.nodeValu e);
var overviewNode:XMLNode = divisionsXML.firstChild.childNodes[i].childNodes[2];
overview.push(overviewNode.firstChild.nodeValue);
var missionNode:XMLNode = divisionsXML.firstChild.childNodes[i].childNodes[3];
mission.push(missionNode.firstChild.nodeValue);
var organizationNode:XMLNode = divisionsXML.firstChild.childNodes[i].childNodes[4];
organization.push(organizationNode.firstChild.node Value);
}
}

magicTuscan
11-09-2009, 04:53 PM
WRONG:

var buttons:Array = [box1_btn, box2_btn, box3_btn];
buttons[i]


RIGHT

var buttons:Array = ["box1_btn", "box2_btn", "box3_btn"];
this[buttons[i]]

NCarolina
11-09-2009, 06:05 PM
Thank you for your response. I tried your suggestion and it doesn't appear to work either.

raghu_thejus
11-10-2009, 04:28 AM
u can do like this


for (var i = 1; i<4; i++) {
this["box"+i+"_btn"].onRollOut = function() {
this._alpha = 100;
};
this["box"+i+"_btn"].onRollOver = function() {
this._alpha = 50;
};
}

magicTuscan
11-10-2009, 08:56 AM
My XML is being called but my buttons are not working properly so the text fields are not populated. The rollout rollover alpha is not working. Any suggestions? This has got to be so simple.

Here is my script:

stop();
var buttons:Array = [box1_btn, box2_btn, box3_btn];
for (var i = 0; i<buttons.length; i++) {
buttons[i].onRollOut = function() {
this._alpha = 100;
};
buttons[i].onRollOver = function() {
this._alpha = 50;
};
}
var divisionsXML:XML = new XML();
var office:Array = new Array();
var leadership:Array = new Array();
var overview:Array = new Array();
var mission:Array = new Array();
var organization:Array = new Array();

for (var i = 0; i<3; i++) {
buttons[i].id = i;
buttons[i].onRelease = function() {
this._parent.loadOffice(this.id);
};
}
function loadOffice(i) {
officetf.text = office[i];
leadershiptf.text = leadership[i];
overviewtf.text = overview[i];
missiontf.text = mission[i];
organizationtf.text = organization[i];
}

divisionsXML.ignoreWhite = true;
divisionsXML.load("divisions.xml");
divisionsXML.onLoad = divisionsLoad;
function divisionsLoad() {
var divisionsNum:Number = divisionsXML.firstChild.childNodes.length;
for (var i = 0; i<divisionsNum; i++) {
var officeNode:XMLNode = divisionsXML.firstChild.childNodes[i].childNodes[0];
office.push(officeNode.firstChild.nodeValue);
var leadershipNode:XMLNode = divisionsXML.firstChild.childNodes[i].childNodes[1];
leadership.push(leadershipNode.firstChild.nodeValu e);
var overviewNode:XMLNode = divisionsXML.firstChild.childNodes[i].childNodes[2];
overview.push(overviewNode.firstChild.nodeValue);
var missionNode:XMLNode = divisionsXML.firstChild.childNodes[i].childNodes[3];
mission.push(missionNode.firstChild.nodeValue);
var organizationNode:XMLNode = divisionsXML.firstChild.childNodes[i].childNodes[4];
organization.push(organizationNode.firstChild.node Value);
}
}

Have you realised that you are writing your code in as2 format.
This is why it's not working.

WRONG:

buttons[i].onRollOut = function() {
this._alpha = 100;
};


RIGHT:

this[buttons[i]].addEventListener(MouseEvent.MOUSE_OVER, doRollOver, false, 0, true);
this[buttons[i]].addEventListener(MouseEvent.MOUSE_OUT, doRollOut, false, 0, true);


private function doRollOver(e : MouseEvent) : void {
e.currentTarget.alpha = 1;
}

private function doRollOut(e : MouseEvent) : void {
e.currentTarget.alpha = .5;
}

NCarolina
11-10-2009, 01:41 PM
Thank you both for your help!