티스토리 뷰

728x90
반응형

머 일단 닝길이 좆또다~


ExternalInterface addCallback 머 웹에 올리면 그냥 무리없이 될때가 많긴 하다.


하지만 로컬에서 크롬이나 파이어폭스 실행시ExternalInterface.addCallback은 아예 되질 않는다. 


왜 그럴까 닝길이~ 요새같은 때에 그냥 짜증난다.


웹에서 찾아봤는데 


1. Security.allowDomain("*"); 도메인을 넣거나~ *으로 표시 하란다.--> 내 결론은 니미 아니올시다~


2. Flash Player 업뎃~---> 니미 이것도 아니올시다.


3. <embed  name="TestMain"  embed 태그에 name을 설정 ---> 절반만 맞다~


4. <param name="allowScriptAccess" value="always" /> 하란다~---> 닝길이 보안설정 그냥 폴더로 두면 된다규~



쨌건 여러 뻘짓 끝에~ 내가 그냥 이것저것 해보기로................ 결국 삽질이 장땡이란 건가~ 그리고는~하나씩 뜯어봤다.    


console.log로 본 결과~~ 플래시에서 호출하는 메서드가 has no method 란다.


닝길이 왜 없는겨~ 왜~왜~


올해 언제였던가 여름인가 봄인가 그때 업뎃이후 이 모냥이다.


여튼 또 웹에 올리고 보니 또 된다. 우 하하 별 그지같은~


쨌든 그래서 has no method니까 has method로 인식시키면 되는거 아닌가~ 라는 생각과 함께


머 그냥 인식못하는 문제라면 단순히 딜레이 걸어서 호출하면 되겠지~


결과는 된다. ㅋㅋㅋㅋ




아래는 html 코드이다.


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">

<head>

<title>ExternalTest</title>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<style type="text/css" media="screen">

html, body { height:100%; background-color: #ffffff;}

body { margin:0; padding:0; overflow:hidden; }

</style>

<script>

var EventM=EventM || {};

EventM.CLICK="click";

                EventM.MOUSE_OVER="mouseover";

                 EventM.MOUSE_OUT="mouseout";

        EventM.MOUSE_DOWN="mousedown";


EventM.addEventListener=function ( target, type, handler ){

        if( target.addEventListener ){

           target.addEventListener( type, handler, false );

    }else if( target.attachEvent ){

       target.attachEvent( "on"+type, handler );

    }else{

           target["on"+type]=handler;

    }

}

window.onload=function(){

var btn=document.getElementById("flashObjCall");

EventM.addEventListener( btn, "click", flashCallFunc );

}

    

function flashCallFunc(){

      callFlash( "a", 1, "dkdkdk", true );

}

</script>

</head>

<body>

<div>

<button id="flashObjCall">button</button>

</div>

<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="550" height="400" id="ExternalTest" align="middle">

<param name="movie" value="ExternalTest.swf" />

<param name="quality" value="high" />

<param name="bgcolor" value="#ffffff" />

<param name="play" value="true" />

<param name="loop" value="true" />

<param name="wmode" value="window" />

<param name="scale" value="showall" />

<param name="menu" value="true" />

<param name="devicefont" value="false" />

   <param name="salign" value="" />

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

        <embed src="ExternalTest.swf" name="ExternalTest" id="ExternalTest" width="550" height="400" />

</body>

</html>




아래는 as3.0~ 

as에서 미리 js 함수를 생성해주어서 자바스크립트단에서는 그냥 플래시에서 지정한 함수만 호출하게끔하게 했다.

물론 자바스크립트에서 함수 선언시 인자값도 맘대로 던져줄 수 있다.

단지 개발할때 서로 함수명이라던지 인자값에 대한 상의는 어느정도는 맞추어야 할듯~

나같은 경우~문서로 명시해서 준다.


package oddeye.control
{
	import flash.external.ExternalInterface;
	import flash.net.navigateToURL;
	import flash.net.URLRequest;
	
	/**
	 * ...
	 * @author ....
	 */
	public class ExternalControl
	{
		public function ExternalControl()
		{
		
		}
		
		/**
		 * 자바스크립트 함수 호출하기~
		 * @param	func
		 * @param	... args 인자값이 있다면 순서대로 입력하면 된다.~
		 */
		public static function call( func, ... args ):void
		{
			if  ( args.length > 0 )
			{
				ExternalInterface.call( func, args );
			}
			else
			{
				ExternalInterface.call( func );
			}
		}
		
		
		/**
		 *
		 * @param	jsName  html에서 as를 호출할 js 함수명~
		 * @param	func  html에서 호출시 실행할 함수
		 * @param	...args  js가 인자값을 가지고 있는경우 대입. \n타입은 반드시 String이여야 한다.
		 */
		public static function callJS( jsName:String, func:Function ):void
		{
			ExternalInterface.addCallback( jsName, func );
		}
		
		/**
		 * 미리 html에 js생성해 놓기 무조건 addJS 메서드를 초기에 선언해놔야한다~
		 * @param	funcName
		 * @example 
		 
		              ExternalControl.addJS("callToFlash");
			      ExternalControl.callJS( "callToFlash", externalFunc );
				  
				  private function externalFunc(...args):void
		          {
			           ExternalControl.alertCall( "플래시externalFunc 함수 실행" );
			           var len:int = args.length;
			           for ( var i:int = 0; i < len; i++)
			           {
				            var txt:TextField = TextFmt.getText( String( args[i] ), 0, 20 );
				            addChild( txt );
				            txt.x = (txt.width + 10) * i;
			            }
		          }
		 

*/ public static function addJS( funcName:String ):void { ExternalInterface.call( "eval", ExternalControl.callBackJS( funcName ) ); } public static function callBackJS( funcName:String ):String { var js:String = ""; var flashID:String = String( ExternalInterface.objectID ); js += "function callFlash(){"; js += " var params=Array.prototype.slice.call( arguments );"; js += " if( /MSIE 6/.test( navigator.userAgent ) || /MSIE 7/.test( navigator.userAgent ) ){ "; js += " window[ "+"'"+flashID+"'"+" ]."+funcName+"( params );"; js += " }else if( /MSIE 8/.test( navigator.userAgent ) || /MSIE 9/.test( navigator.userAgent ) ){ "; js += " document["+"'"+flashID+"'"+"]."+funcName+"( params );"; js += " }else{ "; js += " setTimeout( function(){ document["+"'"+flashID+"'"+"]."+funcName+"( params ); }, 500 );"; js += " }"; js += "}"; return js; } public static function getObjectID():* { return ExternalControl.alertCall( String( ExternalInterface.objectID ) ); } /** * alert 창 띄우기 * @param value */ public static function alertCall( value:* ):void { var alertValue:*=( value is String )? "alert( '" + value + "')" : "alert("+value+")"; ExternalInterface.call( alertValue ); } /** * type check * @param value */ public static function alertTypeof( value:* ):void { var alertValue:*=( value is String )? "alert(typeof '" + value + "')" : "alert(typeof "+value+")"; ExternalInterface.call( alertValue ); } } }


728x90
반응형
댓글