SHOW:
|
|
- or go back to the newest paste.
| 1 | typedef Xywh = {x:Float, y:Float, width:Float, height:Float};
| |
| 2 | ||
| 3 | - | using PlaceTools; |
| 3 | + | class MyButton extends flash.display.Sprite{public function new() super()}
|
| 4 | ||
| 5 | using Main; | |
| 6 | ||
| 7 | class Main extends flash.display.Sprite | |
| 8 | {
| |
| 9 | public function new() | |
| 10 | {
| |
| 11 | super(); | |
| 12 | [new MyButton(), new MyButton(), new MyButton()].distribute(20, PlaceTools.HORIZONTAL); | |
| 13 | } | |
| 14 | ||
| 15 | public static function main() | |
| 16 | {
| |
| 17 | flash.Lib.current.addChild(new Main()); | |
| 18 | } | |
| 19 | } | |
| 20 | ||
| 21 | ||
| 22 | - | case HORIZONTAL: arr[i].rightOf(arr[i-1], padding); |
| 22 | + | |
| 23 | - | default: trace(not implemented in this example); |
| 23 | + | |
| 24 | public static var HORIZONTAL:String = "horizontal"; | |
| 25 | ||
| 26 | public static function rightOf(target:Xywh, ref:Xywh, ?padding:Int=0, ?align:Bool=true, ?width:Float=0, ?height:Float=0):Void | |
| 27 | {
| |
| 28 | target.x = ref.x + ref.width + padding; | |
| 29 | - | //------------------------------------ |
| 29 | + | |
| 30 | - | //var btn1 = new MyButton(); //extends Sprite |
| 30 | + | |
| 31 | - | [btn1, btn2, btn3].distribute(20, PlaceTools.HORIZONTAL); |
| 31 | + | |
| 32 | } | |
| 33 | - | //Compiler error: Array<MyButton> has no field distribute |
| 33 | + | |
| 34 | {
| |
| 35 | - | //changing |
| 35 | + | |
| 36 | - | public static function distribute(arr:Array<Xywh>, ?padding:Int=0, ?dtype:String="horizontal") |
| 36 | + | |
| 37 | - | //into: |
| 37 | + | |
| 38 | - | public static function distribute(arr:Array<Dynamic>, ?padding:Int=0, ?dtype:String="horizontal") |
| 38 | + | |
| 39 | - | //runtime error : btn1 has no field rightOf |
| 39 | + | case HORIZONTAL: |
| 40 | arr[i].rightOf(arr[i-1], padding); | |
| 41 | ||
| 42 | default: | |
| 43 | trace("not implemented in this example");
| |
| 44 | } | |
| 45 | } | |
| 46 | } | |
| 47 | } |