ActionScript3 㧠JSONP ãæ±ãã©ã¤ãã©ãª
AS3 㧠JSONP ãæ±ããã©ã¤ãã©ãªãã±ã£ã¨æ¢ããæãç¡ãã£ãã®ã§ä½ãã¾ããã
URLLoader ã¨ã»ã¨ãã©åãæãã«ä½¿ãã¾ãããã¨ãã°ã¯ã¦ãªããã¯ãã¼ã¯ã® JSONP ãªã
// ãã©ã¦ã¶ã§è¡¨ç¤ºãã¦ãããã¡ã¤ã³ã®ã»ãã¥ãªãã£è¨±å¯ // swf ã®ãã¡ã¤ã³ãåããªãå¿ è¦ãªã JSONPLoader.allowCurrentDomain(); var loader:JSONPLoader = new JSONPLoader(); loader.addEventListener(Event.COMPLETE, function(e:Event):void { log(e.target.data); // target.data ã« JSON ã§æ¸¡ã£ã¦ãããã¼ã¿ãæ ¼ç´ããã¦ãã }); loader.addEventListener(IOErrorEvent.IO_ERROR, function(e:IOErrorEvent):void { // ããã«æ¥ãã®ã¯ã¿ã¤ã ã¢ã¦ãã®æã®ã¿ãããã©ã«ã30ç§ã log('error!'); }); // loader.callbackQueryName = 'callback'; ã³ã¼ã«ããã¯ã®ã¯ã¨ãªåãæå®ãããã©ã«ã㯠'callback' loader.load('http://b.hatena.ne.jp/entry/json/?url=' + encodeURIComponent('http://d.hatena.ne.jp/secondlife/'));
swf ãå¼ã³åºã html ã«ã¯ãswf ã®å¼ã³åºãå ã®ãã¡ã¤ã³ãéãå ´åããã©ã¡ã¼ã¿ allowScriptAccess ã always ã«æå®ããå¿ è¦ãããã¾ãã
<param name="allowScriptAccess" value="always" />
ãã® AS3 ã³ã¼ããå®è¡ãã¦ã¿ãã¨
#<Object:{0:tech, 1:programming, 2:ruby, 3:ajax, 4:javascript, 5:ajax, 6:#<Object:{tags:, timestamp:2007/07/17 23:03:06, comment:, user:konu2}>, 7:#<Object:{0:hatena, 1:blog, 2:computer, user:hobby_hobby, // 以ä¸ç¶ã
ãªæã㧠AS3 ã®ãªãã¸ã§ã¯ãã«ãããã³ã°ãã*1åãåããã¨ãåºæ¥ã¾ããExternalInterface#addCallback ã§æå®ããã³ã¼ã«ããã¯é¢æ°ããswf ã®å¼ã³åºãå ãå¥ãã¡ã¤ã³ã®å ´åãSecurity#allowDomain ãé©åã«è¨å®ããªãã¨
uncaught exception: Error calling method on NPObject! [plugin exception: Error in Actionscript. Use a try/catch block to find error.].
ã¨ããã¨ã©ã¼ãåºã¦åµã£ãç½ ãallowScriptAccess ã ããããã¡ã ã£ãã®ã«æ°ã¥ããªãã£ãâ¦(ããã¥ã¡ã³ãã«ã¡ããã¨è¼ã£ã¦ã)ã
*1:ExternalInterface 㧠eval ãã¦ãã ãã ãã©