Guest User

Untitled

a guest
Jun 18th, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.71 KB | None | 0 0
  1.  
  2. /* in 'actions', do:
  3.  
  4. var tl = new TheLine(this);
  5. addChild(tl);
  6. */
  7.  
  8.  
  9.  
  10. package {
  11.  
  12. import flash.display.Sprite;
  13. import flash.display.*;
  14. import flash.events.*;
  15. import flash.text.*;
  16. import flash.geom.*;
  17.  
  18.  
  19.  
  20. public class TheLine extends Sprite
  21. {
  22.  
  23. private var angle:Number = 0;
  24.  
  25.  
  26.  
  27. var factor:Number = 1.0;
  28.  
  29. var y0:Number = 200;
  30. var x0:Number = 100;
  31. var w:Number = 200;
  32. var h:Number = 32;
  33.  
  34.  
  35. var itsMC:Sprite = new Sprite(); // this is the actual line and hash marks
  36.  
  37. var rect:Rectangle = new Rectangle(x0, y0, w, h);
  38.  
  39. /*
  40. REGARDING HOW 'height' and 'width' seem to mess things up:
  41. DormantOden: pokey19: if you use another sprite, say called MC. Then you can do this.addChild(this.MC); then change thats height/width and things
  42. DormantOden: that should effinatly work. I do that for everything
  43. */
  44.  
  45. public function TheLine(par:DisplayObject)
  46. {
  47.  
  48. x = x0;
  49. y = y0;
  50.  
  51.  
  52.  
  53. this.graphics.beginFill(0xDDDDDD);
  54. this.graphics.drawRect(0, 0, w, -h); // this rect will contain the line
  55.  
  56. //itsMC.x = this.x;
  57. //itsMC.y = this.y;
  58.  
  59. this.addChild(itsMC);
  60.  
  61.  
  62.  
  63.  
  64.  
  65. drawMC();
  66.  
  67. //addEventListener(Event.ENTER_FRAME,transLine);
  68. }
  69.  
  70. function drawTicks()
  71. {
  72. itsMC.graphics.lineStyle(1, 0x000000);
  73.  
  74. // draw major units
  75. itsMC.graphics.moveTo(itsMC.x, itsMC.y);
  76. itsMC.graphics.lineTo(itsMC.x, itsMC.y - h);
  77.  
  78. itsMC.graphics.moveTo(itsMC.x + w, itsMC.y);
  79. itsMC.graphics.lineTo(itsMC.x + w, itsMC.y - h);
  80.  
  81. // draw half-way mark
  82. itsMC.graphics.moveTo(itsMC.x + w/2, itsMC.y);
  83. itsMC.graphics.lineTo(itsMC.x + w/2, itsMC.y - h/2);
  84.  
  85. // now draw the little ticks
  86. var i:Number;
  87. var factor:Number = w/10;
  88. var offset:Number;
  89. for(i=0; i<10; i++)
  90. {
  91. offset = i*factor;
  92. itsMC.graphics.moveTo(itsMC.x + offset, itsMC.y);
  93. itsMC.graphics.lineTo(itsMC.x + offset, itsMC.y - h/4);
  94. }
  95.  
  96. }
  97.  
  98.  
  99.  
  100. function drawMC()
  101. {
  102. itsMC.graphics.clear();
  103.  
  104. itsMC.graphics.lineStyle(1, 0x000000);
  105. itsMC.graphics.moveTo(0, 0);
  106. itsMC.graphics.lineTo(w, 0);
  107.  
  108. drawTicks();
  109.  
  110.  
  111. }
  112.  
  113.  
  114.  
  115. function transLine(event:Event):void
  116. {
  117. angle+=.01;
  118. var cos:Number = Math.cos(angle);
  119. var sin:Number = Math.sin(angle);
  120. /*
  121. this.transform.matrix = new Matrix(cos, sin,
  122. -sin, cos,
  123. 300, 200);
  124. */
  125.  
  126.  
  127. }
  128.  
  129. public function stretchLine(n:Number)
  130. {
  131. itsMC.transform.matrix = new Matrix(n, 0,
  132. 0, 1,
  133. 0, 0);
  134. trace(itsMC.width);
  135. w *= n;
  136. drawMC();
  137. }
  138.  
  139.  
  140.  
  141.  
  142.  
  143. } // end of class
  144. } // end of package
Add Comment
Please, Sign In to add comment