6 Replies Latest reply on Jun 2, 2009 7:24 AM by N.H.L.

    merge 2 code and script doesn't work anymore

    N.H.L.

      I have 2 AS2 codes (I think). One is a carousel gallery script that lets pictures flying in a circle. And the second code is the one that let words fly, downloaden from http://www.levitated.net/daily/levTextSpace.html.

      The scripts work seperatly, but once i merge the codes together the levTextSpace doesn't work anymore. And I can't find where the problem is. Fla file is included.

       

      Carousel gallery:

      picData = new XML();
      picData.ignoreWhite = true;
      picData.onLoad = loadXML;
      picData.load("md_photos.xml");
      function loadXML() {
           _root.createEmptyMovieClip("thumbnails", 1);
           images = new Array();
           for (i=0; picData.firstChild.childNodes[i].firstChild.nodeValue != undefined; i++) {
                images.push(picData.firstChild.childNodes[i].firstChild.nodeValue);
           }
           thumbnails._x = 750;
           thumbnails._y = 75;
           imageLoading = true;
           numObjects = images.length;
           objectsInScene = new Array();
           focalLength = 750;
           spin = 0;
           _root.thumbnailSize = 350/((numObjects)/9);
           displayPane = function () {
                var angle = this.angle+spin;
                var x = Math.cos(angle)*this.radius;
                var z = Math.sin(angle)*this.radius;
                var y = this.y;
                var scaleRatio = focalLength/(focalLength+z);
                this._x = x*scaleRatio;
                this._y = y*scaleRatio;
                this._xscale = -(this._yscale=100*scaleRatio);
                this._xscale *= Math.sin(angle);
                this.swapDepths(Math.round(-z));
           };
           angleStep = 2*Math.PI/numObjects;
           for (i=0; i<numObjects; i++) {
                thumbnail = thumbnails.createEmptyMovieClip("thumbnail_"+i, i);
                myPic = thumbnail.createEmptyMovieClip("picHolder", 1);
                myPic.loadMovie(images[i]);
                thumbnail.angle = angleStep*i;
                thumbnail.radius = 650;
                thumbnail.x = Math.cos(thumbnail.angle)*thumbnail.radius;
                thumbnail.z = Math.sin(thumbnail.angle)*thumbnail.radius;
                thumbnail.y = 0;
                thumbnail.display = displayPane;
                thumbnail.drawBox(_root.thumbnailSize);
                thumbnail.buttonize(i);
                thumbnail.notLoaded = true;
                objectsInScene.push(thumbnail);
           }
           panCamera = function () {
                spin -= 0.001;
                for (var i = 0; i<objectsInScene.length; i++) {
                     objectsInScene[i].display();
                }
           };
           thumbnails.onEnterFrame = panCamera;
           _root.onEnterFrame = function() {
                for (i=0; i<images.length; i++) {
                     if ((_root.thumbnails["thumbnail_"+i].picHolder.getBytesLoaded()/_root.thumbnails["thumbnail_"+i].picHolder.getBytesTotal() == 1) && _root.thumbnails["thumbnail_"+i].notLoaded) {
                          if (_root.thumbnails["thumbnail_"+i].picHolder._width>=_root.thumbnails["thumbnail_"+i].picHolder._height) {
                               _root.thumbnails["thumbnail_"+i].picHolder._yscale = _root.thumbnails["thumbnail_"+i].picHolder._xscale=(100*(1-(_root.thumbnails["thumbnail_"+i].picHolder._width-_root.thumbnailSize)/(_root.thumbnails["thumbnail_"+i].picHolder._width)));
                               _root.thumbnails["thumbnail_"+i].picHolder._y = (_root.thumbnailSize-_root.thumbnails["thumbnail_"+i].picHolder._height)/2;
                          }
                          if (_root.thumbnails["thumbnail_"+i].picHolder._width<=_root.thumbnails["thumbnail_"+i].picHolder._height) {
                               _root.thumbnails["thumbnail_"+i].picHolder._yscale = _root.thumbnails["thumbnail_"+i].picHolder._xscale=(100*(1-(_root.thumbnails["thumbnail_"+i].picHolder._height-_root.thumbnailSize)/(_root.thumbnails["thumbnail_"+i].picHolder._height)));
                               _root.thumbnails["thumbnail_"+i].picHolder._x = (_root.thumbnailSize-_root.thumbnails["thumbnail_"+i].picHolder._width)/2;
                          }
                          if (_root.thumbnails["thumbnail_"+i].picHolder._width == _root.thumbnails["thumbnail_"+i].picHolder._height) {
                               _root.thumbnails["thumbnail_"+i].picHolder._yscale = _root.thumbnails["thumbnail_"+i].picHolder._xscale=(100*(1-(_root.thumbnails["thumbnail_"+i].picHolder._width-_root.thumbnailSize)/(_root.thumbnails["thumbnail_"+i].picHolder._width)));
                               _root.thumbnails["thumbnail_"+i].picHolder._x = _root.thumbnails["thumbnail_"+i].picHolder._y=0;
                          }
                          _root.thumbnails["thumbnail_"+i].picHolder._alpha = 80;
                          _root.thumbnails["thumbnail_"+i].notLoaded = false;
                     }
                     if ((_root.thumbnails["thumbnail_"+i].picHolder.getBytesLoaded()/_root.thumbnails["thumbnail_"+i].picHolder.getBytesTotal()<1)) {
                     }
                }
           };
      }
      

       

      levTextSpace:

      // register root as environment
      Object.environment = _root;

      // create camera object
      this.cam = {x:0, y:0, z:500, dx:0, dy:0, dz:-500};

      // set environmental constants
      this.fl = 1000;

      // create 'space' to which all words will be attached
      this.createEmptyMovieClip("space", 2);
      // center 'space' on the stage
      space._x = 800;
      space._y = 900;

      // a string of words related to the wind
      this.keywords = "no-nonsense  full-service partner  co-creation  innovation  keep it simple  technical expertise  integral design method  successful products  teamwork  designers engineers  design for (dis)assembly  sustainability  ecological  smart  ideation  feasability study  ergonomic analysis  imagineering  trade off matrix  prototyping  consultancy  technology  problemsolvers  open-minded  multi-disciplinary  imagination  creative minds  passionated  user centered  strategy  added value";
      // convert the string of words into an array of words
      this.wordList = new Array();
      this.wordList = this.keywords.split("  ");

      // create one instance for each word in the list
      for (n=0; n<this.wordList.length; n++) {
          // pick a word from the list
          var word = Object.environment.wordList[n];
          var x = random(600)-(300);
          var y = random(400)-(200);
          var z = random(Object.environment.fl*2)-Object.environment.fl;
         
          // create an instance of the keyWord object
          nombre = "word"+String(depth++);
          initialization = {txtword: word, x: x, y: y, z: z};
          space.attachMovie("keyWord", nombre, depth, initialization);
          trace(nombre);
      }

      this.onEnterFrame = function() {
          this.cam.dz += 5;
          // move the camera to its destination
          this.cam.x += (this.cam.dx-this.cam.x)/10;
          this.cam.y += (this.cam.dy-this.cam.y)/10;
          this.cam.z += (this.cam.dz-this.cam.z)/30;
      }

        • 1. Re: merge 2 code and script doesn't work anymore
          kglad Adobe Community Professional & MVP

          you have conflicting onEnterFrame loops.  change one of them so they are not applied to the same movieclip/timeline.

          • 2. Re: merge 2 code and script doesn't work anymore
            N.H.L. Level 1

            Maybe a really stupid question, but how can I do that?

            By merging the 2 onEnterFrame together on one frame?

             

            And another problem I don't know how to solve it.

            When the words is flying around, I want to add boundaries that they only appear in the grey area and not in the white area (above) that is reserved for the gallery images. How can I add boundaries?

            • 3. Re: merge 2 code and script doesn't work anymore
              kglad Adobe Community Professional & MVP
              change the highlighted text

              :

              picData = new XML();
              picData.ignoreWhite = true;
              picData.onLoad = loadXML;
              picData.load("md_photos.xml");
              function loadXML() {
                   _root.createEmptyMovieClip("thumbnails", 1);
                   images = new Array();
                   for (i=0; picData.firstChild.childNodes[i].firstChild.nodeValue != undefined; i++) {
                        images.push(picData .firstChild.childNodes[i].firstChild.nodeValue);
                   }
                   thumbnails._x = 750;
                   thumbnails._y = 75;
                   imageLoading = true;
                   numObjects = images.length;
                   objectsInScene = new Array();
                   focalLength = 750;
                   spin = 0;
                   _root.thumbnailSize = 350/((numObjects)/9);
                   displayPane = function () {
                        var angle = this.angle+spin;
                        var x = Math.cos(angle)*this.radius;
                        var z = Math.sin(angle)*this.radius;
                        var y = this.y;
                        var scaleRatio = focalLength/(focalLength+z);
                        this._x = x*scaleRatio;
                        this._y = y*scaleRatio;
                        this._xscale = -(this._yscale=100*scaleRatio);
                        this._xscale *= Math.sin(angle);
                        this.swapDepths(Mat h.round(-z));
                   };
                   angleStep = 2*Math.PI/numObjects;
                   for (i=0; i<numObjects; i++) {
                        thumbnail = thumbnails.createEmptyMovieClip("thumbnail_"+i, i);
                        myPic = thumbnail.createEmptyMovieClip("picHolder", 1);
                        myPic.loadMovie(ima ges[i]);
                        thumbnail.angle = angleStep*i;
                        thumbnail.radius = 650;
                        thumbnail.x = Math.cos(thumbnail.angle)*thumbnail.radius;
                        thumbnail.z = Math.sin(thumbnail.angle)*thumbnail.radius;
                        thumbnail.y = 0;
                        thumbnail.display = displayPane;
                        thumbnail.drawBox(_ root.thumbnailSize);
                        thumbnail.buttonize (i);
                        thumbnail.notLoaded = true;
                        objectsInScene.push (thumbnail);
                   }
                   panCamera = function () {
                        spin -= 0.001;
                        for (var i = 0; i<objectsInScene.length; i++) {
                           & nbsp; objectsInScene[i].display();
                        }
                   };
                   thumbnails.onEnterFrame = panCamera;
                   _root.onEnterFrame = function() {
                        for (i=0; i<images.length; i++) {
                           & nbsp; if ((_root.thumbnails["thumbnail_"+i].picHolder.getBytesLoaded()/_root.thumbnails["thumbnail_"+i].picHolder.getBytesTotal() == 1) && _root.thumbnails["thumbnail_"+i].notLoaded) {
                           & nbsp;      if (_root.thumbnails["thumbnail_"+i].picHolder._width>=_root.thumbnails["thumbnail_"+i].picHolder._height) {
                           & nbsp;           _root.thu mbnails["thumbnail_"+i].picHolder._yscale = _root.thumbnails["thumbnail_"+i].picHolder._xscale=(100*(1-(_root.thumbnails["thumbnail_"+i].picHolder._width-_root.thumbnailSize)/(_root.thumbnails["thumbnail_"+i].picHolder._width)));
                           & nbsp;           _root.thu mbnails["thumbnail_"+i].picHolder._y = (_root.thumbnailSize-_root.thumbnails["thumbnail_"+i].picHolder._height)/2;
                           & nbsp;      }
                           & nbsp;      if (_root.thumbnails["thumbnail_"+i].picHolder._width<=_root.thumbnails["thumbnail_"+i].picHolder._height) {
                           & nbsp;           _root.thu mbnails["thumbnail_"+i].picHolder._yscale = _root.thumbnails["thumbnail_"+i].picHolder._xscale=(100*(1-(_root.thumbnails["thumbnail_"+i].picHolder._height-_root.thumbnailSize)/(_root.thumbnails["thumbnail_"+i].picHolder._height)));
                           & nbsp;           _root.thu mbnails["thumbnail_"+i].picHolder._x = (_root.thumbnailSize-_root.thumbnails["thumbnail_"+i].picHolder._width)/2;
                           & nbsp;      }
                           & nbsp;      if (_root.thumbnails["thumbnail_"+i].picHolder._width == _root.thumbnails["thumbnail_"+i].picHolder._height) {
                           & nbsp;           _root.thu mbnails["thumbnail_"+i].picHolder._yscale = _root.thumbnails["thumbnail_"+i].picHolder._xscale=(100*(1-(_root.thumbnails["thumbnail_"+i].picHolder._width-_root.thumbnailSize)/(_root.thumbnails["thumbnail_"+i].picHolder._width)));
                           & nbsp;           _root.thu mbnails["thumbnail_"+i].picHolder._x = _root.thumbnails["thumbnail_"+i].picHolder._y=0;
                           & nbsp;      }
                           & nbsp;      _root.thumbnails["thumbnail_"+i].picHolder._alpha = 80;
                           & nbsp;      _root.thumbnails["thumbnail_"+i].notLoaded = false;
                           & nbsp; }
                           & nbsp; if ((_root.thumbnails["thumbnail_"+i].picHolder.getBytesLoaded()/_root.thumbnails["thumbnail_"+i].picHolder.getBytesTotal()<1)) {
                           & nbsp; }
                        }
                   };
              }
              

               

              levTextSpace:

              // register root as environment
              Object.environment = _root;

              // create camera object
              this.cam = {x:0, y:0, z:500, dx:0, dy:0, dz:-500};

              // set environmental constants
              this.fl = 1000;

              // create 'space' to which all words will be attached
              this.createEmptyMovieClip("space", 2);
              // center 'space' on the stage
              space._x = 800;
              space._y = 900;

              // a string of words related to the wind
              this.keywords = "no-nonsense  full-service partner  co-creation  innovation  keep it simple  technical expertise  integral design method  successful products  teamwork  designers engineers  design for (dis)assembly  sustainability  ecological  smart  ideation  feasability study  ergonomic analysis  imagineering  trade off matrix  prototyping  consultancy  technology  problemsolvers  open-minded  multi-disciplinary  imagination  creative minds  passionated  user centered  strategy  added value";
              // convert the string of words into an array of words
              this.wordList = new Array();
              this.wordList = this.keywords.split("  ");

              // create one instance for each word in the list
              for (n=0; n<this.wordList.length; n++) {
                  // pick a word from the list
                  var word = Object.environment.wordList[n];

              // changing the next 3 lines probably will change where the words appear
                  var x = random(600)-(300);
                  var y = random(400)-(200);
                  var z = random(Object.environment.fl*2)-Object.environment.fl;
                 
                  // create an instance of the keyWord object
                  nombre = "word"+String(depth++);
                  initialization = {txtword: word, x: x, y: y, z: z};
                  space.attachMovie("keyWord", nombre, depth, initialization);
                  trace(nombre);
              }
              this.createEmptyMovieClip("loopMC",this.getNextHighestDepth);
              loopMC.onEnterFrame = function() {

                  this.cam.dz += 5;
                  // move the camera to its destination
                  this.cam.x += (this.cam.dx-this.cam.x)/10;
                  this.cam.y += (this.cam.dy-this.cam.y)/10;
                  this.cam.z += (this.cam.dz-this.cam.z)/30;
              }

              • 4. Re: merge 2 code and script doesn't work anymore
                N.H.L. Level 1

                No, the loopMC doesn't work, it even freeze the words.

                 

                And the second problem: it is about the flying route through the gallery script. When I change the position, the words still flying through the image.

                • 5. Re: merge 2 code and script doesn't work anymore
                  kglad Adobe Community Professional & MVP

                  then you may need to find out what you're doing with the 2nd part of your script.   there's more coding that just that.

                   

                  but you can hope for some luck and try to changing the environment and see if that works:

                   

                  // register root as environment

                  this.createEmptyMovieClip("loopMC",this.getNextHighestDepth);
                  Object.environment = this.loopMC;

                   

                  // create camera object
                  loopMC.cam = {x:0, y:0, z:500, dx:0, dy:0, dz:-500};

                   

                  // set environmental constants
                  loopMC.fl = 1000;

                   

                  // create 'space' to which all words will be attached
                  loopMC.createEmptyMovieClip("space", 2);
                  // center 'space' on the stage
                  space._x = 800;
                  space._y = 900;

                   

                  // a string of words related to the wind
                  loopMC.keywords = "no-nonsense  full-service partner  co-creation  innovation  keep it simple  technical expertise  integral design method  successful products  teamwork  designers engineers  design for (dis)assembly  sustainability  ecological  smart  ideation  feasability study  ergonomic analysis  imagineering  trade off matrix  prototyping  consultancy  technology  problemsolvers  open-minded  multi-disciplinary  imagination  creative minds  passionated  user centered  strategy  added value";
                  // convert the string of words into an array of words
                  loopMC.wordList = new Array();
                  loopMC.wordList = loopMC.keywords.split("  ");

                   

                  // create one instance for each word in the list
                  for (n=0; n<this.wordList.length; n++) {
                      // pick a word from the list
                      var word = Object.environment.wordList[n];

                  // changing the next 3 lines probably will change where the words appear
                      var x = random(600)-(300);
                      var y = random(400)-(200);
                      var z = random(Object.environment.fl*2)-Object.environment.fl;
                     
                      // create an instance of the keyWord object
                      nombre = "word"+String(depth++);
                      initialization = {txtword: word, x: x, y: y, z: z};
                      space.attachMovie("keyWord", nombre, depth, initialization);
                      trace(nombre);
                  }

                  loopMC.onEnterFrame = function() {

                      this.cam.dz += 5;
                      // move the camera to its destination
                      this.cam.x += (this.cam.dx-this.cam.x)/10;
                      this.cam.y += (this.cam.dy-this.cam.y)/10;
                      this.cam.z += (this.cam.dz-this.cam.z)/30;
                  }

                  • 6. Re: merge 2 code and script doesn't work anymore
                    N.H.L. Level 1

                    Thank you very much, the two script are running together.

                     

                    But the flying through the gallery problem is still there.

                    Now, I tried to put a mask in front of the grey area which is only visible for the words, but that doesn't work.

                    Also I find the prototype part of the flying words, is a hack possible to let the words flying around in an area of 1600px X 500px?

                    I am confused

                     

                    #initclip
                    function KeyWord() {
                         this.onEnterFrame = this.render;
                    }
                    
                    KeyWord.prototype = new MovieClip();
                    
                    KeyWord.prototype.render = function() {
                         var zActual = Object.environment.fl+this.z-Object.environment.cam.z;
                    
                         if (zActual>0) {
                              var scale = Object.environment.fl/zActual;
                              this._x = (this.x-Object.environment.cam.x)*scale;
                              this._y = (this.y-Object.environment.cam.y)*scale;
                              this._xscale = scale*100;
                              this._yscale = scale*100;
                              this._alpha = 100 - 99 * zActual/Object.environment.fl*.5;
                         } else {
                              this.z += Object.environment.fl*2;
                              this.x += random(600)-300;
                              this.y += random(400)-200;
                         }
                    };
                    KeyWord.prototype.setWord = function(s) {
                         this.txtWord = s;
                    };
                    KeyWord.prototype.setPosition = function(x, y, z) {
                         this.x = x;
                         this.y = y;
                         this.z = z;
                    };
                    Object.registerClass("keyWord", KeyWord);
                    #endinitclip