4 Replies Latest reply on Aug 22, 2009 8:44 PM by shintashi

    Can I change the layer depth of a Drawing?

    shintashi Level 1

      I've got a spiral

      -----------------

      function spiral(centerX, centerY, radius, sides, coils, rotation){
          with(this){
              moveTo(centerX, centerY);
              var awayStep = radius/sides;
              var aroundStep = coils/sides;// 0 to 1 based.
              var aroundRadians = aroundStep * 2 * Math.PI;
              rotation *= 2 * Math.PI;
              for(var i=1; i<=sides; i++){
                  var away = i * awayStep;
                  var around = i * aroundRadians + rotation;
                  var x = centerX + Math.cos(around) * away;
                  var y = centerY + Math.sin(around) * away;
                  lineTo(x, y);
              }
          }
      }

       

      lineStyle(4,0xCCB700);
      spiral(260.5,438.0,125,DOTS,XE,0);

      --------------

       

      and I want some movie clips to appear infront as well as behind it, but right now it always appears on the bottom layer. Is there a way to attach the drawing to a movie clip or something so I can change it's depth?

        • 1. Re: Can I change the layer depth of a Drawing?
          Ned Murphy Adobe Community Professional & MVP

          You could probably just have that code on the timeline of a movieclip in the library and use attachMovie to add it.

           

          I didn't look too closely at the code, but I'm thinking you could replace "this" with an empty movieclip and have something to control the depth of that way.

          • 2. Re: Can I change the layer depth of a Drawing?
            shintashi Level 1

            putting the code inside another movie clip works, but the code (I displayed a fraction of it) is so intertangled with the main code that taking it out (of the main) would be like one of those sci fi movies with a device lodged in the victim's spine/brain - you know the ones where the doctor says "if we remove it, it would probably kill them".

             

            Meanwhile trying to attach it to a movie clip has failed (by changing "this" to "my_mc"). I tried large and small, centered and corner alignments, but all of them produced nothing. There must be some way of rewording the spiral function so it attaches to something other than the main time line, and it would save several hours of headaches playing "Doctor".

            • 3. Re: Can I change the layer depth of a Drawing?
              Ned Murphy Adobe Community Professional & MVP

              Unfortunately, if you're only showing part of the code involved, there isn't much anyone will be able to do to help you around this using either approach.

              • 4. Re: Can I change the layer depth of a Drawing?
                shintashi Level 1

                here's the code, it's not too many lines of code, just convoluted.

                ------------------------------------------------

                 

                bolt_range = 0;
                rod_base = rod._y;
                spring_ybase = spring._yscale;
                spring_xbase = spring._xscale;
                spring_x = spring_cap._y;
                speed = 0;
                activation = 1;

                 

                $a = clamp._rotation;
                $b = clamp2._rotation;
                $c = mgearB._rotation;
                $d = sgearA._rotation;
                $e = mgearA._rotation;
                $f = saw._x;
                $g = saw.sgear1._rotation;
                $h = gear19._rotation;
                $i = mgearC._rotation;

                 

                //-----

                 

                six00 = 6;
                tdbase = turndial._y;

                 

                function spiral(centerX, centerY, radius, sides, coils, rotation){
                    with(this){// Draw within the clip calling the function.
                        moveTo(centerX, centerY);
                        var awayStep = radius/sides;
                        var aroundStep = coils/sides;// 0 to 1 based.
                        var aroundRadians = aroundStep * 2 * Math.PI;
                        rotation *= 2 * Math.PI;
                        for(var i=1; i<=sides; i++){
                            var away = i * awayStep;
                            var around = i * aroundRadians + rotation;
                            var x = centerX + Math.cos(around) * away;
                            var y = centerY + Math.sin(around) * away;
                            lineTo(x, y);
                        }
                    }
                }
                //lineStyle(thickness, 0xColor);
                // spiral(centerX, centerY, radius, sides, coils, rotation).

                 

                XE = 2;
                XPLUS = 0;
                marker = 0;
                rewind = 0;
                active = 0;
                springframebase = springframe._rotation;

                 

                 

                 

                onEnterFrame = function(){
                markerval.text = marker;
                switchact.onRelease = function(){active++;}
                if(active > 2){active = 0;}
                if(ticker == 2){ticker = 0;}

                 

                if(active == 0){switchact._rotation = 0;   
                six00 = 0;
                turndial._y = tdbase;
                lock._rotation = 0;
                gear1._xscale = 100;
                gear1._yscale = 100;
                }

                 

                 

                 


                if(active == 1){switchact._rotation = +40;   
                if(Key.isDown(Key.UP)){six00++;}
                if(Key.isDown(Key.DOWN)){six00--;}
                if(six00 > 600){six00 = 600;}
                if(six00 < 6){six00 = 6;}
                springframe._rotation = springframebase - rewind + marker;
                marker = marker - 1;
                    XPLUS--;
                  this.clear();
                lineStyle(4,0xCCB700);
                spiral(260.5,438.0,125,DOTS,XE,0);
                windgear._rotation += six00;
                turndial._y = tdbase - 10;
                lock._rotation = -10;
                gear1._xscale = 100;
                gear1._yscale = 100;

                 

                }

                 

                //windup;
                if(active == 2){switchact._rotation = -40;   
                springframe._rotation = springframebase - rewind + marker;
                six00 = 0;
                gear1._xscale = 80;
                gear1._yscale = 80;

                 

                windgear._rotation -= 6;
                rewind = rewind - 1;
                    XPLUS++;
                  this.clear();
                lineStyle(4,0xCCB700);
                spiral(260.5,438.0,125,DOTS,XE,0);
                turndial.play();
                turndial._y = tdbase;
                lock.play();
                }

                 

                 

                 


                speed.text = six00;
                //1:60

                 

                seconds._rotation += six00;
                gear1._rotation += six00;
                gear2a._rotation -= six00/2;
                gear2b._rotation += six00/4;
                gear2c._rotation -= six00/8;
                gear2d._rotation += six00/16;
                gear15._rotation -= six00/24;
                gear25._rotation += six00/60;
                minutes._rotation += six00/60;

                 

                //1:3600
                missing._rotation -= six00/60;
                gear2cq._rotation += six00/120;
                hourfix._rotation -= six00/240;
                gear2dq._rotation += six00/240;
                gear15q._rotation -= six00/360;
                gear2q._rotation += six00/720;
                hours._rotation += six00/720;

                 

                //winding mode;

                 

                DOTS = XE * 50;
                XE = 8 + XPLUS/360;

                 

                //winding watch
                if(Key.isDown(Key.LEFT)){marker = marker + 18;
                XPLUS++;
                  this.clear();
                lineStyle(4,0xCCB700);
                spiral(260.5,438.0,125,DOTS,XE,0);

                 

                XE = 8 + XPLUS/20;

                 

                }

                 


                if(Key.isDown(Key.RIGHT)){marker = marker - 18;
                    XPLUS--;
                  this.clear();
                lineStyle(4,0xCCB700);
                spiral(260.5,438.0,125,DOTS,XE,0);

                 


                }

                 

                //----
                    spring._yscale = spring_ybase - (bolt_range/0.73);
                    spring._xscale = spring_xbase + (bolt_range/Math.PI);

                 

                    rod._y = rod_base + bolt_range;
                    spring_cap._y = spring_x + bolt_range;

                 

                if(bolt_range < 0){bolt_range = 0; speed = 0;}
                if(bolt_range > 65){bolt_range = 65;}

                 

                if(clamp.catchdot.hitTest(mgearC.catchdot)){activation = 0;}
                if(rod.tip2.hitTest(catchdot3)){activation = 1;
                clamp._rotation = $a;
                clamp2._rotation = $b;
                mgearB._rotation = $c;
                sgearA._rotation = $d;
                mgearA._rotation = $e;
                saw._x = $f;
                saw.sgear1._rotation = $g;
                gear19._rotation = $h;
                mgearC._rotation = $i;
                }
                //key was "DOWN" switched to SPACE to avoid interference
                if(Key.isDown(Key.SPACE)){speed++; bolt_range = bolt_range +1 ;}   
                else{bolt_range = bolt_range - (1 + speed/2);}
                //if(Key.isDown(Key.UP)){bolt_range = bolt_range - 1; transferrod._rotation = 0}
                transferrod._rotation = bolt_range * 0.728;
                transferrod.bend._rotation = -bolt_range * 0.414;
                clamp2.pullbeam._rotation = +clamp2._rotation;
                rodgear._rotation = bolt_range * Math.PI;
                doublerodgear._rotation = -bolt_range * Math.PI/2;
                quadrodgear._rotation = bolt_range * Math.PI/4;
                octrodgear._rotation = -bolt_range * Math.PI/8;
                octrodgear.transferrod._rotation = bolt_range * Math.PI/8;
                octrodgear.transferrod.bend._rotation = bolt_range * Math.PI/60;
                lock._rotation = octrodgear._rotation * 1.25;
                dotval.text = activation;

                 

                if(activation == 0){
                if(rod.tip2.hitTest(clamp2.sensor)){clamp._rotation += 5; gear19._rotation -= 5; saw._x += 8.75;}
                }

                 


                if(activation == 1){
                if(rod.tip2.hitTest(clamp.sensor)){clamp._rotation -= 2; gear19._rotation += 2; saw._x -= 3.5;}
                }

                 


                if(rod.tip2.hitTest(clamp2.sensor)){clamp2._rotation -= 2; if(saw.sgear1._rotation != 0){
                    saw.sgear1._rotation -=9; mgearA._rotation -= 6; sgearA._rotation +=9; mgearB._rotation -= 6;
                    mgearC._rotation +=6;}
                }
                if(rod.tip2.hitTest(clamp2.sensor2)){clamp2._rotation += 2;  saw.sgear1._rotation +=9;  
                mgearA._rotation += 6; mgearB._rotation += 6; sgearA._rotation -=9; mgearC._rotation -=6;}

                 

                if(rod.tip2.hitTest(clamp.tip)){if(bolt_range < 26){bolt_range = 26; speed = 0;}}

                 

                 

                 

                }