ADOBE/ ActionScript

플래시 AS3.0 특징 몇가지

AlrepondTech 2011. 11. 15. 18:33
반응형

 

 

 

 

=================================

=================================

=================================

 

 

 

 

 

 

 

출처: http://blog.naver.com/setopia1112?Redirect=Log&logNo=110009101481

1. 동적 클래스 사용가능

dynamic

class Protean {
  private var privateGreeting:String = "hi";
  public var publicGreeting:String = "hello";

 

  function Protean () {
    trace("Protean instance created");
  }
}

 

  var myProtean:Protean = new Protean();
  myProtean.aString = "testing";   

// 동적으로 속성 추가가 가능하다

  myProtean.aNumber = 3;
  myProtean.traceProtean = function () {  // 메소드도 마찬가지로 추가 가능
    trace (this.aString, this.aNumber);
  }
  myProtean.traceProtean(); // output: testing 3

 

 

2. compile check 와 runtime check

function dynamicTest(xParam:Object) {
  if (xParam is String) {
    var myStr:String = xParam; // compiler error in strict mode
    trace("String: " + myStr);
  }
  else if (xParam is Number) {
    var myNum:Number = xParam; // compiler error in strict mode
    trace("Number: " + myNum);
  }
}

 

function dynamicTest(xParam) {
  if (xParam is String) {
    var myStr:String = xParam;
    trace("String: " + myStr);
  }
  else if (xParam is Number) {
    var myNum:Number = xParam;
    trace("Number: " + myNum);
  }
}
dynamicTest(100)
dynamicTest("one hundred");

 

:: complie type 체크를 피하고 런타임에서 체크하길 원한다면

타입형을 제거해 버리면 됨

 

 

3. 패키지 사용시

// SampleCode.as file
package samples {
 

public

class SampleCode {}
}
// CodeFormatter.as file
package samples {
  class CodeFormatter {}
}

 

import samples.SampleCode;
import samples.CodeFormatter;
var mySample:SampleCode = new SampleCode(); // okay, public class
var myFormatter:CodeFormatter = new CodeFormatter(); // error

 

:: 패키지 내 클래스가 Public이 아닐 경우 외부 참조 시 에러 발생

 

 

4. Function Closure 지원

function foo () : Function {
  var x:int = 40;
  function rectArea(y:int) : int { // function closure defined
    return x * y
  }
  return rectArea;
}


function bar () : void {
  var x:int = 2;
  var y:int = 4;
  var myProduct:Function = foo();
  trace( myProduct(4) ); // function closure called
}
bar(); // output: 160

 

 

5. namespace 지원 :: 특별히 쓸데가 있을려나? 흠...

 

=================================

=================================

=================================

 

 

 

반응형