8 Replies Latest reply on Oct 12, 2009 7:58 AM by kglad

    xml thumbnail + onRelease function on each thumbnail

    cosmicvibs

      Hello evryone ! Im trying to create via xml and a for() loop a thumbnails wiewer and each thumbnail have a simple onrelease function.....

      but my probleme is that my 'container' movieClip and 'BT' movieClip dont show when I export the movie...also when i trace() them the output is empty. maybe is because they are inside  x.onLoad(xml){} function ???
      Maybe someone can help me with this one ???
      At the end of the script you can remove // before the trace() function for ckecking in the output panel.

      here is my code:

      xml file: TumbLoader.xml

      <?xml version="1.0" encoding="ISO-8859-1"?>
      <slideshow>
      <photos thumbnail="thumbnail/1.jpg" />
      <photos thumbnail="thumbnail/2.jpg" />
      <photos thumbnail="thumbnail/3.jpg" />
      <photos thumbnail="thumbnail/4.jpg" />
      <photos thumbnail="thumbnail/5.jpg" />
      </slideshow>



      actionscript: a Transparent button  linked for AS as Btb in the library is needed.

      //XML BANK
      var x:XML = new XML();
      x
      .ignoreWhite = true;

      var thumb:Array = new Array();//create array
      var Spc = 0;// space between thumbnail default 0
      var posX = 163;// position x
      var posY = 10;//1st position y

      x
      .onLoad = function(xml) {
         
      var photos:Array = this.firstChild.childNodes;
         
      for (i=0; i<photos.length; i++) {
             
      var Num = i+1;
             
      var WhoIsOn = Num;
             
      var Bt_name = "Bt"+Num;
              thumb
      .push(photos[i].attributes.thumbnail);//put each attributs of thumbnail for each photos node

             
      //for the thumbnails
             
      var Clp_name = "clip"+Num;
             
             
      //i think my probleme start here:---> with container and BT:
             
             
      var container = (container+Num);
             
      var container:MovieClip = this.createEmptyMovieClip(Clp_name, this.getNextHighestDepth());
              container
      .loadMovie(thumb[i],1);
              container
      ._x = posX;
              container
      ._y = posY+Spc;
             
      Spc = Spc+120;// increment the space between thumbnail
             
             
      //for the OnRelease function on the thumbnail
             
      var BT:MovieClip = this.attachMovie("Btb", Bt_name, this.getNextHighestDepth());
              BT
      ._x = posX;
              BT
      ._y = posY+Spc;
              BT
      .whoIsOn = i;
              BT
      .onRelease = function() {
                  trace
      (this.whoIsOn);
             
      };//<---- end of probleme
         
         
      // I USE TRACE() FOR CHECK:
             
      //trace(photos.length); for chek the length of the for loop
             
      //trace(Clp_name);// for check clip name
             
      //trace(thumb[i]);//for check file name
             
      //trace(container);//for chek if container is not empty should say: _level0.Clp_name in the output but it dont
             
      //trace(thumb);//for check array
             
      //trace(BT);//same probleme as container
             
      //trace(Bt_name);//for check button name
             
      //trace(Spc);// for check the positio _Y
         
      }
      };
      x
      .load("TumbLoader.xml");
        • 1. Re: xml thumbnail + onRelease function on each thumbnail
          kglad Adobe Community Professional & MVP

          use trace(this.getNextHighestDepth()) to see if you've used a v2 component that's causing a depth problem for you.

          • 2. Re: xml thumbnail + onRelease function on each thumbnail
            cosmicvibs Level 1

            thanks for reply

            when i put  trace(this.getNextHighestDepth())

            it say 'undefined' in the output panel.

            How i define it ?? do i have to define the depth when I  createEmptyMovieClip() container and BT ?

            • 3. Re: xml thumbnail + onRelease function on each thumbnail
              kglad Adobe Community Professional & MVP

              if you're publishing for less than flash player 7, you can't use getNextHighestDepth().

               

              either change your publish settings or manually control your depths with a variable.  i like to use:

               

              var dep:Number=0;  // to initialize this variable.

               

              // then everytime you need a depth to create or attach a movieclip use:

               

              createEmptyMovieClip(xxx,dep++);

              //or

              attachMovie(xxx,xxx,dep++);

              • 4. Re: xml thumbnail + onRelease function on each thumbnail
                cosmicvibs Level 1

                thx again!

                i try with 'dep++' but it still 'undefined'.
                For the publish setting: itis for flash player 10 and actionscript2 so it should be no probleme using getNextHighestDepth() no ?. Im really lost on this one..... ican send the fla file if needed

                • 5. Re: xml thumbnail + onRelease function on each thumbnail
                  cosmicvibs Level 1

                  i stil dont find the answer.... if someone can help.

                  • 6. Re: xml thumbnail + onRelease function on each thumbnail
                    kglad Adobe Community Professional & MVP

                    then the problem is your use of "this".  in that onLoad() method you're in the scope of your xml instance.

                     

                    use:

                     

                    var tl.MovieClip=this;

                     

                    x.onLoad=function(){

                     

                    .

                    .

                    // and use tl.attachMovie(xx,xxx,tl.getNextHighestDepth());

                    .

                    .

                    }

                    1 person found this helpful
                    • 7. Re: xml thumbnail + onRelease function on each thumbnail
                      cosmicvibs Level 1

                      Hello Kglad!. sorry for the late reply it was late where am I....

                       

                      i think i did like you said :

                       

                      var x:XML = new XML();
                      x.ignoreWhite = true;

                       

                      var thumb:Array = new Array();//create array
                      var Spc = 0;// space between thumbnail default 0
                      var posX = 163;// position x
                      var posY = 10;//1st position y
                      var tl.MovieClip=this;

                       

                      x.onLoad = function() {

                          var photos:Array = this.firstChild.childNodes;
                          for (i=0; i<photos.length; i++) {
                              var Num = i+1;
                              var WhoIsOn = Num;
                              var Bt_name = "Bt"+Num;
                              thumb.push(photos[i].attributes.thumbnail);//put each attributs of thumbnail for each photos node

                       

                              //for the thumbnails

                              var Clp_name = "clip"+Num;

                              var container = (container+Num);
                              var container:MovieClip = tl.createEmptyMovieClip(Clp_name, tl.getNextHighestDepth());
                              container.loadMovie(thumb[i],1);
                              container._x = posX;
                              container._y = posY+Spc;
                              Spc = Spc+120;// increment the space between thumbnail
                             
                              //for the OnRelease function on the thumbnail
                              var BT:MovieClip = tl.attachMovie("Btb", Bt_name, tl.getNextHighestDepth());
                              BT._x = posX;
                              BT._y = posY+Spc;
                              BT.whoIsOn = i;
                              BT.onRelease = function() {
                                  trace(this.whoIsOn);
                              };

                       

                       

                       

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

                       

                      But in the output the script stop at:  'var tl.MovieClip=this;' before the x.onLoad() function

                      • 8. Re: xml thumbnail + onRelease function on each thumbnail
                        kglad Adobe Community Professional & MVP

                        i have a typo.  that should be:

                         

                        var tl:MovieClip=this;

                        1 person found this helpful