/Sketches/TextField/data/additionalHaxeFilesToBeCopiedToProject/Main.hx

https://github.com/davidedc/P5Nitro · Haxe · 107 lines · 55 code · 24 blank · 28 comment · 1 complexity · bcaf914ecb889ac71339388a18514176 MD5 · raw file

  1. import flash.display.MovieClip;
  2. import flash.display.Sprite;
  3. import flash.display.Bitmap;
  4. import flash.display.BitmapData;
  5. class Main extends MovieClip {
  6. public function new () {
  7. super();
  8. // retina display
  9. this.scaleX = 2.0;
  10. this.scaleY = 2.0;
  11. var r:Sprite = new Sprite();
  12. r.graphics.beginFill(0xaaaaff);
  13. r.graphics.drawRect(0,0,300,200);
  14. addChild(r);
  15. var i=0;
  16. var imax=10;
  17. for (i in 0...imax) {
  18. var m=new MovieClip();
  19. var p : flash.text.TextField = new flash.text.TextField();
  20. p.text="Hello1234567 world!";
  21. // autosize doesn't seem to work quite right on the iPhone, so
  22. // we put the whole screen size here for the time being
  23. p.width = 320;
  24. //p.autoSize = flash.text.TextFieldAutoSize.LEFT;
  25. // _text.defaultTextFormat = tf;
  26. p.selectable = false;
  27. p.border = true;
  28. p.borderColor = 0xFF0000;
  29. var ts = new flash.text.TextFormat();
  30. //ts.color=0xFFFF00;
  31. ts.size=40;
  32. //ts.font = "Verdana";
  33. ts.font = "AmericanTypewriter";
  34. // here is a complete list of fonts
  35. // supported in both iPhone 4.2 and iPad 4.2
  36. // http://iosfonts.com/
  37. p.setTextFormat(ts);
  38. p.scaleX=2;
  39. p.alpha=1-i/imax;
  40. /////////// CASE 1 - DRAW BY ADDING TEXTEDIT LAYER
  41. //p.textColor=0x00FF0000; // if draw on TextField layer, this is red
  42. //p.textColor=0x0000FF00; // if draw on TextField layer, this is green
  43. //p.textColor=0x000000FF; // if draw on TextField layer, this is blue
  44. //m.addChild(p);
  45. /////////// END OF CASE 1 - DRAW BY ADDING TEXTEDIT LAYER
  46. /////////// CASE 2- DRAW ON BITMAP AND THEN ADD BITMAP LAYER
  47. //p.textColor=0x000000FF; // if you draw on a bitmap, then this is red
  48. //p.textColor=0x0000FF00; // if you draw on a bitmap, then this is green
  49. p.textColor=0x00FF0000; // if you draw on a bitmap, then this is blue
  50. // You should try to make this bitmap as tighter to the text as possible,
  51. // if you make it as large as the whole screen it's a waste of memory!
  52. // in this case we have to multiply the X by two
  53. // cause the textField has a scalex of 2.
  54. var bitmapData:BitmapData = new BitmapData(Std.int(p.textWidth*2), Std.int(p.height), true, 0x00000000);
  55. //var bitmapData:BitmapData = new BitmapData(2000, 400, true, 0x00000000);
  56. //var bitmapData:BitmapData = new BitmapData(271, Std.int(p.height), true, 0x00000000);
  57. trace("textfield width, height:" + p.width + ", "+p.height); // gives 100,100
  58. trace("2 textfield width, height:" + p.textWidth + ", "+p.textHeight); // gives 270.5,4
  59. bitmapData.draw(p);
  60. var bitmap:Bitmap = new Bitmap();
  61. bitmap.bitmapData = bitmapData;
  62. bitmap.smoothing = true;
  63. m.addChild(bitmap);
  64. /////////// END OF CASE 2- DRAW ON BITMAP AND THEN ADD BITMAP LAYER
  65. var circle2:Sprite = new Sprite();
  66. circle2.graphics.beginFill(0xFFCC00);
  67. circle2.graphics.drawCircle(120, 40, 40);
  68. m.addChild(circle2);
  69. m.x=10*i;
  70. m.y=10*i;
  71. m.alpha=1-(i+1)/imax;
  72. m.scaleX=(i+1)/imax;
  73. m.scaleY=(i+1)/imax;
  74. //
  75. addChild(m);
  76. // use my embedded font
  77. }
  78. }
  79. public static function main() {
  80. var m:Main = new Main();
  81. flash.Lib.current.addChild(m);
  82. }
  83. }