/bin/std/flash9/Lib.hx

http://github.com/Yoomee/clippy · Haxe · 94 lines · 54 code · 16 blank · 24 comment · 9 complexity · ad76df2d01ec4990a3178a1fdb32d255 MD5 · raw file

  1. /*
  2. * Copyright (c) 2005, The haXe Project Contributors
  3. * All rights reserved.
  4. * Redistribution and use in source and binary forms, with or without
  5. * modification, are permitted provided that the following conditions are met:
  6. *
  7. * - Redistributions of source code must retain the above copyright
  8. * notice, this list of conditions and the following disclaimer.
  9. * - Redistributions in binary form must reproduce the above copyright
  10. * notice, this list of conditions and the following disclaimer in the
  11. * documentation and/or other materials provided with the distribution.
  12. *
  13. * THIS SOFTWARE IS PROVIDED BY THE HAXE PROJECT CONTRIBUTORS "AS IS" AND ANY
  14. * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  15. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  16. * DISCLAIMED. IN NO EVENT SHALL THE HAXE PROJECT CONTRIBUTORS BE LIABLE FOR
  17. * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  18. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  19. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  20. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  21. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  22. * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  23. * DAMAGE.
  24. */
  25. package flash;
  26. class Lib {
  27. public static var current : flash.display.MovieClip;
  28. public inline static function getTimer() : Int {
  29. return untyped __global__["flash.utils.getTimer"]();
  30. }
  31. public static function eval( path : String ) : Dynamic {
  32. var p = path.split(".");
  33. var fields = new Array();
  34. var o : Dynamic = null;
  35. while( p.length > 0 ) {
  36. try {
  37. o = untyped __global__["flash.utils.getDefinitionByName"](p.join("."));
  38. } catch( e : Dynamic ) {
  39. fields.unshift(p.pop());
  40. }
  41. if( o != null )
  42. break;
  43. }
  44. for( f in fields ) {
  45. if( o == null ) return null;
  46. o = untyped o[f];
  47. }
  48. return o;
  49. }
  50. public static function getURL( url : flash.net.URLRequest, ?target : String ) {
  51. var f = untyped __global__["flash.net.navigateToURL"];
  52. if( target == null )
  53. f(url);
  54. else
  55. (cast f)(url,target);
  56. }
  57. public static function fscommand( cmd : String, ?param : String ) {
  58. untyped __global__["flash.system.fscommand"](cmd,if( param == null ) "" else param);
  59. }
  60. public static function trace( arg : Dynamic ) {
  61. untyped __global__["trace"](arg);
  62. }
  63. public static function attach( name : String ) : flash.display.MovieClip {
  64. var cl = untyped __as__(__global__["flash.utils.getDefinitionByName"](name),Class);
  65. return untyped __new__(cl);
  66. }
  67. public inline static function as<T>( v : Dynamic, c : Class<T> ) : Null<T> {
  68. return untyped __as__(v,c);
  69. }
  70. #if flash10
  71. public inline static function vectorOfArray<T>( v : Array<T> ) : Vector<T> {
  72. return untyped __vector__(v);
  73. }
  74. public inline static function vectorConvert<T,U>( v : Vector<T> ) : Vector<U> {
  75. return untyped __vector__(v);
  76. }
  77. #end
  78. }