플래시(Flash)와 자바스크립트(Javascript) 연동하기
html의 플래시 삽입태그의 id 값 확인하기
<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="1024" height="580" id="flashJavascript">
html에 자바스크립트 입력
<!-- ###### 여기가 자바스크립트와 플래시 연동하는 함수 입니다. ##### -->
<script language="JavaScript">
function thisMovie(movieName) {
if (navigator.appName.indexOf("Microsoft") != -1) {
return window[movieName];
} else {
return document[movieName];
}
}
function sendPosition( x, y ){
thisMovie("flashJavascript").changePosition( x, y );
}
function receivePosition(valueX, valueY) {
document.forms["form1"].xpos.value = valueX;
document.forms["form1"].ypos.value = valueY;
}
</script>
html에 사용자입력을 받을 html 폼 추가
<form name="form1" onsubmit="return false;">
<input type="text" name="xpos", value="" /><input type="text" name="ypos", value="" />
<input type="button" value="Change" onclick="sendPosition(this.form.xpos.value, this.form.ypos.value);" />
<br />
</form>
ActionScript에서 자바와 연동할 함수 설정하기
// 콜백 추가
ExternalInterface.addCallback( "changePosition", onChangePosition);
public function onChangePosition( _xpos: Number, _ypos: Number ): void
{
test_mc.x = _xpos;
test_mc.y = _ypos;
}
// 자바스크립트 함수 호출
ExternalInterface.call("sendPosition", test_mc.x, test_mc.y );
참조 : http://help.adobe.com/ko_KR/FlashPlatform/reference/actionscript/3/flash/external/ExternalInterface.html