This page was saved using jaction on 2006-09-04 8:33:41.
Address: http://flexdocs.kr/docs/flex2/langref/flash/external/ExternalInterface.html
Title: flash.external.ExternalInterface (Flex™ 2 레퍼런스 가이드)  •  Size: 40892
Packageflash.external
Classpublic final class ExternalInterface
InheritanceExternalInterface Inheritance Object

ExternalInterface 클래스는 외부 API 이며, ActionScript 와 Flash Player 의 컨테이너와의 사이에 직접 통신할 수 있도록(듯이) 하는 어플리케이션 프로그래밍 인터페이스입니다. 컨테이너의 예로서는, JavaScript 가 포함되는 HTML 페이지나, Flash Player 가 포함된 데스크탑 어플리케이션등이 있습니다. JavaScript 와 ActionScript 의 모든 통신에 ExternalInterface 를 사용하는 것을 추천합니다.

HTML 페이지상의 JavaScript 로부터, Flash Player 의 ActionScript 함수를 호출할 수가 있습니다. ActionScript 함수는 값을 돌려줄 수가 있어 JavaScript 는, 호출의 반환값으로서 즉석에서 이 값을 받습니다.

이 기능은 이전의 fscommand() Methods에 대신하는 것입니다.

ExternalInterface 은, 다음의 브라우저와 operating system의 편성에 대응하고 있습니다.

브라우저 operating system
Internet Explorer 5.0 이후  Windows   
Netscape 8.0 이후  Windows   Macintosh 
Mozilla 1.7. 5 이후  Windows   Macintosh 
Firefox 1.0 이후  Windows   Macintosh 
Safari 1.3 이후    Macintosh 

ExternalInterface 를 이용하려면 , 유저의 Web 브라우저가, 일부의 브라우저에 의해 플러그 인 스크립트로서 공개되고 있는 ActiveX 또는 NPRuntime API 의 어느쪽이든을 지원(support)하고 있을 필요가 있습니다. http://www.mozilla.org/projects/plugins/npruntime.html 를 참조해 주세요.

메모 : HTML 페이지에 SWF 파일을 포함하는 경우,<object> 태그와 <embed> 태그의 id 속성과 name 속성에 다음의 캐릭터가 포함되지 않은 것을 확인합니다. (. ),-,+,*,/, 및 \.

ActionScript 로부터, HTML 페이지에 대해서 다음 일을 실행할 수 있습니다.

HTML 페이지의 JavaScript 로부터, 다음 일을 실행할 수 있습니다.

메모 : Flash Player 는 현재, HTML 폼에 포함된 SWF 파일을 지원(support)하고 있습니다.

View the examples

See also

flash.system.fscommand()
ExternalInterface API 를 사용한 Flex 로부터 JavaScript 에의 액세스
JavaScript 로부터의 Flex 에의 액세스
Flex 에 있어서의 ExternalInterface API 시큐러티에 대해
External API 에 대해
ExternalInterface 클래스의 사용


Public property
 property정의
  available : Boolean
[static][read-only] 이 Player 가 외부 인터페이스를 갖춘 컨테이너에 포함되어 있는지 어떤지를 나타냅니다.
ExternalInterface
 Inheritedconstructor : Object
특정의 object 인스턴스의 클래스 object 또는 constructor    함수에의 참조입니다.
Object
  objectID : String
[static][read-only] Internet Explorer 의 <object> 태그의 id 속성을 돌려주는지, 또는 Netscape 의 <embed> 태그의 name 속성을 돌려줍니다.
ExternalInterface
 Inheritedprototype : Object
[static] 클래스 또는 함수 object의 prototype object에의 참조입니다.
Object
Public Methods
 Methods정의
  addCallback (functionName:String , closure:Function ):void
[static] ActionScript Methods를 컨테이너로부터 호출해 가능한 것으로 해 등록합니다.
ExternalInterface
  call (functionName:String , ... arguments):*
[static] Flash Player 컨테이너로 공개되고 있는 함수를 호출해, 필요에 따라서 인수를 건네줍니다.
ExternalInterface
 InheritedhasOwnProperty (name:String ):Boolean
object로 지정된 property가 정의되고 있는지 어떤지를 나타냅니다.
Object
 InheritedisPrototypeOf (theClass:Object ):Boolean
Object 클래스의 인스턴스가, Parameters로서 지정된 object의 prototype 체인내에 있을지 어떨지를 나타냅니다.
Object
 InheritedpropertyIsEnumerable (name:String ):Boolean
지정된 property가 존재해, 열거 가능한가 어떤가를 나타냅니다.
Object
 InheritedsetPropertyIsEnumerable (name:String , isEnum:Boolean = true):void
루프 처리에 대한 다이나믹 property의 가용성을 설정합니다.
Object
 InheritedtoString ():String
지정된 object의 string 표현을 돌려줍니다.
Object
 InheritedvalueOf ():Object
지정된 object의 원시적치를 돌려줍니다.
Object
property의 상세
availableproperty
available:Boolean   [read-only]

이 Player 가 외부 인터페이스를 갖춘 컨테이너에 포함되어 있는지 어떤지를 나타냅니다. 외부 인터페이스를 이용할 수 있는 경우, 이 property는 true 가 됩니다. 이용할 수 없는 경우에는 false 가 됩니다.

메모 : HTML 로 외부 API 를 사용하는 경우, JavaScript Methods를 호출하기 전에는 항상, HTML 가 완전하게 로드 되고 있는 것을 확인할 필요가 있습니다.

Implements
    public static function get available():Boolean

See also


Example
다음의 예에서는,available property를 사용해, 외부 인터페이스를 갖춘 컨테이너내에 Player 가 포함되어 있는지 어떤지를 결정합니다.
  package {
    import flash.text.TextField;
    import flash.display.MovieClip;
    import flash.external.ExternalInterface;
  
    public class extint_test extends MovieClip {
      public function extint_test() {
        var isAvailable:Boolean = ExternalInterface.available;
        var availTxt:TextField = new TextField();
        availTxt.text = isAvailable.toString();
        addChild(availTxt);
      }
    }
  }
  

objectIDproperty 
objectID:String   [read-only]

Internet Explorer 의 <object> 태그의 id 속성을 돌려주는지, 또는 Netscape 의 <embed> 태그의 name 속성을 돌려줍니다.

Implements
    public static function get objectID():String

See also

Methods의 상세
addCallback()Methods
public static function addCallback(functionName:String , closure:Function ):void

ActionScript Methods를 컨테이너로부터 호출해 가능한 것으로 해 등록합니다. addCallBack() 의 호출이 성공하면, Flash Player 내에 등록되어 있는 함수를 컨테이너내의 JavaScript 나 ActiveX 로부터 호출할 수가 있습니다.

Parameters
functionName:String — 컨테이너가 함수를 호출할 수가 있는 이름입니다.
 
closure:Function — 호출하는 함수폐포입니다. 이것은 독립한 함수로 하는 일도, object 인스턴스의 Methods를 참조하는 Methods폐포로 할 수도 있습니다. Methods폐포를 건네주는 것으로, 특정의 object 인스턴스의 Methods로 콜백을 실제로 다이렉트 할 수 있습니다.

Throws
Error — 컨테이너가 입호를 지원(support)하지 않는 경우, 에러가 슬로우 됩니다. 이것은 Windows 용의 Internet Explorer, Mozilla 1.7. 5 이후, 또는 Firefox 1.0 이후와 같은 NPRuntime API 를 사용하는 브라우저에서만 지원(support)됩니다.
 
SecurityError — 지정된 이름을 사용한 콜백이, 액세스 하고 있지 않는 Sandbox 내에서 이미 ActionScript 에 의해 추가되고 있습니다. 이 콜백을 덧쓰기할 수 없습니다. 이것은, 최초로 addCallback() Methods를 호출한 ActionScript 이 Security.allowDomain() Methods도 호출하도록(듯이) 하는 것에 의해 회피할 수 있는 경우가 있습니다.
 
SecurityError — 컨테이너 환경이 시큐러티 샌드 박스에 속하고 있기 위해서(때문에), 호출측의 코드에 액세스권이 없습니다. 이 문제를 해결하기 위해서, 다음 일을 실행합니다.
  1. 포함되어 있는 HTML 페이지내의 SWF 파일의 <object> 태그로, 다음의 Parameters를 설정합니다.

    <param name="allowScriptAccess" value="always" />

  2. SWF 파일로, 다음의 ActionScript 를 추가합니다.

    flash.system.Security.allowDomain(sourceDomain)

See also

call()Methods 
public static function call(functionName:String , ... arguments):*

Flash Player 컨테이너로 공개되고 있는 함수를 호출해, 필요에 따라서 인수를 건네줍니다. 지정된 함수를 이용할 수 없는 경우는 null 를 돌려줍니다. 그 이외의 경우는, 함수의 반환값을 돌려줍니다. 재귀 호출은할 수 없습니다. 재귀 호출의 경우는 null 를 돌려줍니다.

컨테이너가 HTML 페이지인 경우, 이 Methods는 <script> 엘리먼트에 둘러싸인 JavaScript 함수를 호출합니다.

컨테이너가 무엇인가 다른 ActiveX 컨테이너의 경우, 이 Methods는, 지정된 이름으로 FlashCall ActiveX 이벤트를 발행해, 그 이벤트는 컨테이너에 의해 처리됩니다.

컨테이너가 Netscape 플러그 인을 호스트 하고 있는 경우, 새로운 NPRuntime 인터페이스용의 custom 지원(support)를 기술하는지, HTML 컨트롤을 포함된 후에 그 컨트롤내에 Flash Player 를 포함할 수가 있습니다. HTML 컨트롤을 포함하고 있을 경우, 네이티브 컨테이너 어플리케이션과 교환하는 JavaScript 인터페이스를 통해서 Flash Player 와 통신할 수 있습니다.

Parameters
functionName:String — 컨테이너내에 있는 호출처 함수의 이름입니다.
 
... arguments — 컨테이너내의 함수에게 건네지는 인수입니다. 임의의 Parameters를 지정할 수가 있어 복수의 Parameters를 지정하는 경우는 칸마로 단락짓습니다. Parameters에는 임의의 ActionScript 데이터형을 사용할 수 있습니다. 호출처가 JavaScript 함수인 경우, ActionScript 의 데이터형은 JavaScript 의 데이터형에 자동적으로 정렬화 됩니다. 호출처가 다른 ActiveX 컨테이너인 경우, Parameters는 요구 메세지안에 encode 됩니다.

반환값
* — 컨테이너로부터 받은 응답입니다. 호출해에 실패했을 경우는,null 가 돌려주어져 에러가 슬로우 됩니다. 실패 원인으로서는, 컨테이너에 해당하는 함수가 존재하지 않는 경우, 인터페이스를 이용할 수 없는 경우, 재귀가 발생했을 경우, 시큐러티상의 문제가 있는 경우등이 있습니다.

Throws
Error — 컨테이너가 발호를 지원(support)하지 않는 경우, 에러가 슬로우 됩니다. 이것은 Windows 용의 Internet Explorer, Mozilla 1.7. 5 이후, 또는 Firefox 1.0 이후와 같은 NPRuntime API 를 사용하는 브라우저에서만 지원(support)됩니다.
 
SecurityError — 컨테이너 환경이 시큐러티 샌드 박스에 속하고 있기 위해서(때문에), 호출측의 코드에 액세스권이 없습니다. 이것을 회피하려면 , 컨테이너의 환경에 있어,allowScriptAccess (통상, HTML 의 allowScriptAccess <object>/<embed> 태그)에 적절한 값을 설정합니다.

See also

Examples

다음의 예에서는, Flash Player 및 HTML 컨테이너간에 데이터를 송신하는 방법을 나타냅니다.

package {
    import flash.display.Sprite;
    import flash.events. *;
    import flash.external.ExternalInterface;
    import flash.text.TextField;
    import flash.utils.Timer;
    import flash.text.TextFieldType;
    import flash.text.TextFieldAutoSize;

    public class ExternalInterfaceExample extends Sprite {
        private var input:TextField;
        private var output:TextField;
        private var sendBtn:Sprite;

        public function ExternalInterfaceExample() {
            input = new TextField();
            input.type = TextFieldType.INPUT;
            input.background = true;
            input.border = true;
            input.width = 350;
            input.height = 18;
            addChild(input);

            sendBtn = new Sprite();
            sendBtn.mouseEnabled = true;
            sendBtn.x = input.width + 10;
            sendBtn.graphics.beginFill(0xCCCCCC);
            sendBtn.graphics.drawRoundRect(0, 0, 80, 18, 10, 10);
            sendBtn.graphics.endFill();
            sendBtn.addEventListener(MouseEvent.CLICK, clickHandler);
            addChild(sendBtn);

            output = new TextField();
            output.y = 25;
            output.width = 450;
            output.height = 325;
            output.multiline = true;
            output.wordWrap = true;
            output.border = true;
            output.text = "Initializing...\n";
            addChild(output);

            if (ExternalInterface.available) {
                try {
                    output.appendText("Adding callback...\n");
                    ExternalInterface.addCallback("sendToActionScript", receivedFromJavaScript);
                    if (checkJavaScriptReady()) {
                        output.appendText("JavaScript is ready. \n");
                    } else {
                        output.appendText("JavaScript is not ready, creating timer. \n");
                        var readyTimer:Timer = new Timer(100, 0);
                        readyTimer.addEventListener(TimerEvent.TIMER, timerHandler);
                        readyTimer.start();
                    }
                } catch (error:SecurityError) {
                    output.appendText("A SecurityError occurred: " + error.message + "\n");
                } catch (error:Error) {
                    output.appendText("An Error occurred: " + error.message + "\n");
                }
            } else {
                output.appendText("External interface is not available for this container. ");
            }
        }
        private function receivedFromJavaScript(value:String) :void {
            output.appendText("JavaScript says: " + value + "\n");
        }
        private function checkJavaScriptReady() :Boolean {
            var isReady:Boolean = ExternalInterface.call("isReady");
            return isReady;
        }
        private function timerHandler(event:TimerEvent) :void {
            output.appendText("Checking JavaScript status...\n");
            var isReady:Boolean = checkJavaScriptReady();
            if (isReady) {
                output.appendText("JavaScript is ready. \n");
                Timer(event.target). stop();
            }
        }
        private function clickHandler(event:MouseEvent) :void {
            if (ExternalInterface.available) {
                ExternalInterface.call("sendToJavaScript", input.text);
            }
        }
    }
}


상기의 ActionScript 코드를 테스트하려면 , 다음의 HTML 템플릿을 사용해, 생성된 SWF 파일을 포함합니다.
 <! -- saved from url=(0014) about:internet -->
 <html lang="en">
 <head>
 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
 <title>ExternalInterfaceExample</title>
 <script language="JavaScript">
     var jsReady = false;
     function isReady() {
         return jsReady;
      }
     function pageInit() {
         jsReady = true;
         document.forms["form1"]. output.value += "\n" + "JavaScript is ready. \n";
      }
     function thisMovie(movieName) {
         if (navigator.appName.indexOf("Microsoft") ! = -1) {
             return window[movieName];
         } else {
             return document[movieName];
          }
      }
     function sendToActionScript(value) {
         thisMovie("ExternalInterfaceExample"). sendToActionScript(value);
      }
     function sendToJavaScript(value) {
         document.forms["form1"]. output.value += "ActionScript says:" + value + "\n";
      }
 </script>
 </head>
 <body onload="pageInit() ;">
  
     <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
             id="ExternalInterfaceExample" width="500" height="375"
             codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab">
         <param name="movie" value="ExternalInterfaceExample.swf" />
         <param name="quality" value="high" />
         <param name="bgcolor" value="#869ca7" />
         <param name="allowScriptAccess" value="sameDomain" />
         <embed src="ExternalInterfaceExample.swf" quality="high" bgcolor="#869ca7"
             width="500" height="375" name="ExternalInterfaceExample" align="middle"
             play="true" loop="false" quality="high" allowScriptAccess="sameDomain"
             type="application/x-shockwave-flash"
             pluginspage="http://www.macromedia.com/go/getflashplayer">
         </embed>
     </object>
  
     <form name="form1" onsubmit="return false;">
         <input type="text" name="input" value="" />
         <input type="button" value="Send" onclick="sendToActionScript(this.form.input.value) ;" /><br />
         <textarea cols="60" rows="20" name="output" readonly="true">Initializing...</textarea>
     </form>
  
 </body>
 </html>
  








 

코멘트가 추가되었을 경우, 메일로 받기. | 코멘트 리포트

현재의 페이지: http://flexdocs.kr/docs/flex2/langref/flash/external/ExternalInterface.html