4 Replies Latest reply on Nov 12, 2009 11:39 AM by cosmicus26

    probleme setting value in a variable via a combobox

    cosmicus26

      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[i].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);
      
        • 1. Re: probleme setting value in a variable via a combobox
          Ned Murphy Adobe Community Professional & MVP

          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.

          1 person found this helpful
          • 2. Re: probleme setting value in a variable via a combobox
            cosmicus26 Level 1

            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);

            • 3. Re: probleme setting value in a variable via a combobox
              Ned Murphy Adobe Community Professional & MVP

              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.

              1 person found this helpful
              • 4. Re: probleme setting value in a variable via a combobox
                cosmicus26 Level 1

                Ok i do it another way to be honest, i have a movieclip (filmstrip) in my scene that contain a thumbnail , this thumbnail is loaded by an xml. on my scene i have the combobox with categorie , i want that when i choose a categorie in my combobox in my scene the xml file to be loaded in my movieclip filmstrip change. but it dont

                so i my scene i have :

                 

                stop();
                //function
                function Text_Thumbnail(textThumb) {
                    myText_txt.text = textThumb;
                }
                function Tload(string) {
                    url = string;
                }
                var link1:Array = new Array();
                var LINK:String;
                var url:String;
                
                var x:XML = new XML();
                x.ignoreWhite = true;
                x.onLoad = function(success) {
                    var photos:Array = this.firstChild.childNodes;
                    for (i=0; i<photos.length; i++) {
                        _root.link1.push(photos[i].attributes.link1);
                    }
                    Tload(link1[0]);
                    _root.filmstrip.LINK= url;
                  
                };
                x.load("category.xml");
                
                
                var cbListener:Object = new Object();
                
                cbListener.change = function(event_obj:Object) {
                    trace(select.selectedItem.label);
                    if (select.selectedItem.label == "Last updated") {
                        _root.Tload(link1[0]);
                        
                    } else if (select.selectedItem.label == "Special") {
                        _root.Tload(link1[1]);
                        
                    }
                    _root.filmstrip.LINK= url;
                  
                };
                
                // Add Listener.
                select.addEventListener("change",cbListener);
                

                 

                 

                 

                and this is the script inside my thumbnail clip (filmstrip) (i didnt put all the code)

                 

                var T:XML = new XML();
                T.ignoreWhite = true;
                T.onLoad = etc etcetc....        
                    }
                    
                };
                T.load(LINK); //here is what i want to change with the combobox of the scene