I’ve been looking for days now and I just can’t find it.
Info:
- I’m loading xml into a couple textfields which all works fine
- These textfields are scripted to also be buttons, so when I push them, some more info shows up with a picture or what not
- I have 2 buttons to show me older and newers news if there are more nodes in the xml then there are textfields
- The nodes get loaded when I push the button, but then the problem shows up
Problem:
- In the 2 buttons is a variable called “I” for counting purposes.
- The functions I made to show the info have a “function bla(id:number)” so “I” gets loaded into them whenever I call the function “bla(i);”
- So what happens is, the textfields get loaded in the beginning, I push the button, the next set of info is loaded, but when I push those textfields for more info, it’s the same info as the previous set
- When I trace(id); in the functions it shows up “0 6” instead of just “6” and it always adds another number if I push those 2 buttons and then a textfield again “0 6 0 6”
Solution:
So I need those functions to not remember their values, and always clear their id and fill them again when I push the buttons for the next set.
Sorry if it’s a bit complicated
Code:
//declaration
var container:XMLList;
var _xml:String = "myxml.xml";
var i:int = 0;
//XML load function
var _lader:URLLoader = new URLLoader();
_lader.addEventListener(Event.COMPLETE, laadXMLCompleet);
_lader.load(new URLRequest(_xml));
function laadXMLCompleet(e:Event):void {
_lader.removeEventListener(Event.COMPLETE, laadXMLCompleet);
container = new XMLList(_lader.data);
//load functions to show the info
toonInformatie2(i);
toonInformatie3(i+1);
}
btn2.addEventListener(MouseEvent.CLICK, prevn);
function prevn(Event:MouseEvent):void{
//next 6 nodes get loaded
i=i+6;
toonInformatie2(i);
toonInformatie3(i+1);
trace(i);
}
//---Small textfield 1---
function toonInformatie2(id:Number):void{
txtmc0.txt0.mouseEnabled = false;
txtmc0.buttonMode = true;
txtmc0.addEventListener(MouseEvent.CLICK, onClickHandler);
function onClickHandler(myEvent:MouseEvent){
//function to show more info
toonInformatie(id);
trace(id);
}
//links to xml
var date = container.item[id].datum.text() +":";
var title = container.item[id].title.text();
//load text in textfield
txtmc0.txt0.htmlText = date + title;
}
}
//textfield 2
function toonInformatie3(id:Number):void{
//same code as previous but in another textfield
}