* [Flash] Javascript에서 ActionScript내의 함수 호출방법
작업중 플래시에서 외부의 jsp를 통해 데이터를 읽어야 하는 일이 생겼다.
그래서 생각한건 페이질 Reload~~! ㅡㅡㅋ
영 뽀대가 나지 않는다.
그래서 찾아보던중 flash.external.ExternalInterface의 addCallback() 메소드를 이용해 Javascript에서
ActionScript의 함수 호출이 가능하다는걸 알았다.
* ActionSctipt
import flash.external.ExternalInterface;
System.security.allowDomain("*");
var methodName:String = "goHome"; // Javascript에서 호출할 메소드명
var instance:Object = null; // 메서드에서 this
가 확인하는 객체
var method:Function = goToMacromedia; // ActionScript내에서 실행될 메소드명
var wasSuccessful:Boolean = ExternalInterface.addCallback(methodName, instance, method);
var txtField:TextField = this.createTextField("txtField", this.getNextHighestDepth(), 0, 0, 200, 50);
txtField.border = true;
txtField.text = wasSuccessful.toString();
// 호출시 실행될 메소드
function goToMacromedia() {
txtField.text = "http://www.macromedia.com";
getURL("http://www.macromedia.com/", "_self");
}
※ 생성자에 넣어 놓구 사용하면 좋을듯.
* HTML
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title> New Document </title>
</head>
<body>
<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0" width="200" height="50" id="externalInterfaceExample">
<param name="movie" value="addCallback_test.swf" />
<param name="quality" value="high" />
<param name="allowScriptAccess" value="always" />
<embed src="addCallback_test.swf" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="192" height="192" allowScriptAccess="always" showLiveConnect="true" name="externalInterfaceExample"></embed>
</object>
<form>
<input type="button" onclick="callExternalInterface()" value="Call ExternalInterface" />
</form>
<script>
//
function callExternalInterface()
{
thisMovie("externalInterfaceExample").goHome(); // ActionScript의 메소드 호출
}
function thisMovie(movieName)
{
if (navigator.appName.indexOf("Microsoft") != -1) {
return window[movieName]
} else {
return document[movieName]
}
}
</script>
</body>
</html>