6 Replies Latest reply on Sep 16, 2007 1:17 PM by

    duplicateMovieClip

      after successfully creating six movieclips, each holds a different image, within a loop structure that calls duplicateMovieClip,
      i am unable to use these movie clips as a button, ie my_mc.onRelease = function(){}.. does not work, yet debug shows that the
      clips exists and i use the name that debug shows and i can see them..to keep this message short, i have attached pertintent code..
      thanks Don97
        • 1. Re: duplicateMovieClip
          kglad Adobe Community Professional & MVP
          code attached to a movieclip is lost when that movieclip is the target of a loadMovie() or loadClip() method. to remedy, define your mouse handlers after loading is complete or load into a child of the movieclip that has mouse handlers.
          1 person found this helpful
          • 2. Re: duplicateMovieClip
            thank you for responding, i removed the loadMovie but the resultant duplicate movieclips still do not respond as buttons when created with duplicateMovieClip, actually same thing happens if i use CreateMovieClip..
            Don97
            • 3. Re: duplicateMovieClip
              kglad Adobe Community Professional & MVP
              show the code you used, using the attach code option.
              1 person found this helpful
              • 4. Re: duplicateMovieClip
                function loadXML(loaded) {
                if (loaded) {
                xmlNode = this.firstChild;
                image = [];
                url = [];
                thumbImage = [];
                thmAr = [];
                total = xmlNode.childNodes.length;
                for (i=0; i<total; i++) {
                image = xmlNode.childNodes.childNodes[0].firstChild.nodeValue;
                url = xmlNode.childNodes.childNodes[1].firstChild.nodeValue;
                thumbImage = xmlNode.childNodes.childNodes[2].firstChild.nodeValue;
                }

                firstImage();

                for (j=0;j<total;j++){
                thmAr[j] = showThumb(j);
                trace("thmAr["+j+"] = "+thmAr[j]);
                }
                } else {
                content = "file not loaded!";
                }
                }

                xmlData = new XML();
                xmlData.ignoreWhite = true;
                xmlData.onLoad = loadXML;
                xmlData.load("images.xml");


                /////////////////////////////////////
                listen = new Object();
                listen.onKeyDown = function() {
                if (Key.getCode() == Key.LEFT) {
                prevImage();
                } else if (Key.getCode() == Key.RIGHT) {
                nextImage();
                }
                };
                Key.addListener(listen);
                previous_btn.onRelease = function() {
                prevImage();
                };
                next_btn.onRelease = function() {
                nextImage();
                };
                /////////////////////////////////////
                p = 0;
                this.onEnterFrame = function() {
                filesize = picture.getBytesTotal();
                loaded = picture.getBytesLoaded();
                preloader._visible = true;
                if (loaded != filesize) {
                preloader.preload_bar._xscale = 100*loaded/filesize;
                } else {
                preloader._visible = false;
                if (picture._alpha<100) {
                picture._alpha += 7;
                }
                }
                };
                var intervalCounter:Number = setInterval(nextImage,3000);
                function nextImage() {
                if (p<(total-1)) {
                p++;
                if (loaded == filesize) {
                picture._alpha = 0;
                picture.loadMovie(image[p], 1);
                //desc_txt.text = url[p];
                picture_num();
                }
                }else{
                p=0;
                firstImage();
                }
                }
                function prevImage() {
                if (p>0) {
                p--;
                picture._alpha = 0;
                picture.loadMovie(image[p], 1);
                //desc_txt.text = url[p];
                picture_num();
                }
                }
                function firstImage() {
                if (loaded == filesize) {
                picture._alpha = 0;
                picture.loadMovie(image[0], 1);
                //desc_txt.text = url[0];
                picture_num();
                }
                }
                function picture_num() {
                current_pos = p+1;
                pos_txt.text = current_pos+" / "+total;
                }
                function showThumb(n:Number):MovieClip{
                button.duplicateMovieClip("button"+n,100+n);

                if(n<=4){
                _root["button"+n]._x=80 * n;
                _root["button"+n]._y = 345;
                }else{
                _root["button"+n]._x = 80 * (n-5);
                _root["button"+n]._y = 410;
                }
                // recommended suggestion from kglad
                ////////////////////////////////////////////////
                // _root["button"+n].loadMovie(thumbImage[n]);//
                ////////////////////////////////////////////////
                return _root["button"+n];
                }

                //use thumbnail moveclips as a button
                thmAr[0].onRelease = function(){
                trace("Button 0 Released");}
                _root._level0.button6.onRelease = function(){
                trace("Button 6 Released");}
                n=1;
                _root["button"+n].onRelease = function(){
                trace("Button 1 release");}
                • 5. Re: duplicateMovieClip
                  kglad Adobe Community Professional & MVP
                  again, use the attach code option.
                  1 person found this helpful
                  • 6. Re: duplicateMovieClip
                    problem solved..
                    The problem was not letting the dup function complete before adding the event handlers.

                    I just extended the time line to 12 frames, probably more than enough, then added the event handlers in the frame script..
                    who would have 'thunk it'.. i should probably test for "something" before adding event handlers..
                    don