Skip to main content
Participant
November 12, 2009
Question

probleme setting value in a variable via a combobox

  • November 12, 2009
  • 1 reply
  • 564 views

Hello evrybody! i have a probleme , my probleme is that my string LINK at the end of the script is undefined it should change when i select the categories with my combo box Can someone help me please ???

here is the  xml :category.xml

<?xml version="1.0" encoding="ISO-8859-1"?>
<slideshow>
<area title1="10 Last updated" link1="lastupdated.php"/>
<area title1="Specials" link1="special.php"/>
</slideshow>

here is the scrpt

function Tload(string) {
    url = string;
}

var link1:Array = new Array();
var LINK:String;

var x:XML = new XML();
x.ignoreWhite = true;
x.onLoad = function(success) {
    var urls:Array = this.firstChild.childNodes;
    for (i=0; i<urls.length; i++) {
        _root.link1.push(urls.attributes.link1);
    }
    Tload(link1[0]);
    _root.LINK=url;

};
x.load("category.xml");

//Create Listener Object.
var cbListener:Object = new Object();
// Assign function to Listener Object.
cbListener.change = function(event_obj:Object) {
    trace(select.selectedItem.label);
    if (select.selectedItem.label == "Last updated") {
        _root.Tload(link1[0]);
        //trace(url);
    } else if (select.selectedItem.label == "Special") {
        _root.Tload(link1[1]);
        //trace(url);
    }
    _root.LINK= url;
    trace(LINK);//here it work
};

//add eventListener

select.addEventListener("change",cbListener);

//here is my problem:

trace(LINK);//here it doesnt trace my string LINK ?? so my function Tload(LINK) bellow doesnt work
Tload(LINK);

This topic has been closed for replies.

1 reply

Ned Murphy
Legend
November 12, 2009

Code works in a couple of ways... some code is built into functions and whatnot and sits waiting for things to happen.  Commands like the last two you show, execute as soon as the frame is entered--they aren't being delayed waiting for anything to happen.   That trace at the end of your code is executing before LINK is assigned a value.  Chances are you want to move that tLoad(LINK) call into the change function, after it is assigned.

Participant
November 12, 2009

hello thanks for answering.

It is more complicated , i cant move Load(LINK) call into the change function,because someting else is not going to work after..because i use the value of it in another clip calling it like this: load(__root.url);

Ned Murphy
Legend
November 12, 2009

That doesn't sound complicated, though I can't tell how calling tLoad affects some other load call from what you described. In any case, if you execute tLoad(LINK) before LINK is defined, it won't do much good.