|
| 1 | +package { |
| 2 | +import flash.display.Sprite; |
| 3 | +import flash.display.DisplayObject; |
| 4 | +import flash.text.TextField; |
| 5 | +import flash.text.TextFormat; |
| 6 | +import flash.events.Event; |
| 7 | + |
| 8 | +public class Test extends Sprite { |
| 9 | + private var desc: String = null; |
| 10 | + |
| 11 | + public function Test() { |
| 12 | + stage.scaleMode = "noScale"; |
| 13 | + |
| 14 | + testInteractions(); |
| 15 | + |
| 16 | + trace("Tests finished"); |
| 17 | + } |
| 18 | + |
| 19 | + private function testInteractions() { |
| 20 | + testBoundsUpdate("addChild", function(text:TextField, cb:Function) { |
| 21 | + addChild(text); |
| 22 | + cb(); |
| 23 | + }); |
| 24 | + |
| 25 | + testBoundsUpdate("contains", function(text:TextField, cb:Function) { |
| 26 | + contains(text); |
| 27 | + cb(); |
| 28 | + }); |
| 29 | + |
| 30 | + testBoundsUpdate("hitTestObject as argument", function(text:TextField, cb:Function) { |
| 31 | + hitTestObject(text); |
| 32 | + cb(); |
| 33 | + }); |
| 34 | + |
| 35 | + testBoundsUpdate("setting focus", function(text:TextField, cb:Function) { |
| 36 | + stage.focus = text; |
| 37 | + cb(); |
| 38 | + }); |
| 39 | + |
| 40 | + testBoundsUpdate("resetting focus", function(text:TextField, cb:Function) { |
| 41 | + stage.focus = text; |
| 42 | + cb(); |
| 43 | + }, function(text:TextField) { |
| 44 | + stage.focus = text; |
| 45 | + }); |
| 46 | + |
| 47 | + testBoundsUpdate("setting maskee", function(text:TextField, cb:Function) { |
| 48 | + var maskee = new Sprite(); |
| 49 | + addChild(maskee); |
| 50 | + addChild(text); |
| 51 | + maskee.mask = text; |
| 52 | + cb(); |
| 53 | + }); |
| 54 | + |
| 55 | + testBoundsUpdate("getBounds relative", function(text:TextField, cb:Function) { |
| 56 | + var other = new Sprite(); |
| 57 | + other.x = 0; |
| 58 | + other.y = 0; |
| 59 | + other.width = 10; |
| 60 | + other.height = 5; |
| 61 | + addChild(other); |
| 62 | + addChild(text); |
| 63 | + trace("// getBounds = " + other.getBounds(text)); |
| 64 | + cb(); |
| 65 | + }); |
| 66 | + |
| 67 | + testBoundsUpdate("getRect relative", function(text:TextField, cb:Function) { |
| 68 | + var other = new Sprite(); |
| 69 | + other.x = 0; |
| 70 | + other.y = 0; |
| 71 | + other.width = 10; |
| 72 | + other.height = 5; |
| 73 | + addChild(other); |
| 74 | + addChild(text); |
| 75 | + trace("// getRect = " + other.getRect(text)); |
| 76 | + cb(); |
| 77 | + }); |
| 78 | + } |
| 79 | + |
| 80 | + private function testBoundsUpdate(desc: String, fun: Function, before: Function = null):void { |
| 81 | + this.desc = desc; |
| 82 | + var text = new TextField(); |
| 83 | + text.width = 100; |
| 84 | + text.height = 20; |
| 85 | + if (before != null) { |
| 86 | + before(text); |
| 87 | + } |
| 88 | + |
| 89 | + text.autoSize = "center"; |
| 90 | + fun(text, function():void { |
| 91 | + text.wordWrap = true; |
| 92 | + trace("Testing: " + desc); |
| 93 | + trace(" " + text.x + "," + text.y + "," + text.width + "," + text.height); |
| 94 | + }); |
| 95 | + } |
| 96 | +} |
| 97 | +} |
0 commit comments