JSProxy - AS3 ããæèããã« JS ãæä½
AS3 ãã HTML ã®ç¹å®è¦ç´ ã®å
容ãåå¾ããã JS ã®ã¡ã½ãããå¼æ°ã¤ãã¦å¼ã³åºããããå¤ãã»ããããããããã©ããããªã£ã¦ããã®ã§ä½ã£ã¦ã¿ã¾ããã
JSProxy.proxy ããã㯠new JSProxy() 㧠JSProxy ã®ã¤ã³ã¹ã¿ã³ã¹ãä½ããé©å½ã«ããããã£ãå¼ã³åºãã¦ãã£ã¦(ãã®æç¹ã§ã¯ã¹ã¿ãã¯ã«ã©ãããå¦çãè¡ãããæ¸ãã¦ãã ã)ãæå¾JSãæ¬å½ã«å©ãã¦å¤ãåå¾ãã¡ã½ããå¼ã³åºããè¡ãããã¨ãã¯ãããããã£ã®é ã« $ ãã¤ãã¾ãã
// ã¢ã©ã¼ãé¢æ°ãå®è¡ JSProxy.proxy.$alert('foo'); // body ã®æ¬æãåå¾ var body:String = JSProxy.proxy.document.body.$innerHTML; // body ã® style ãå¤æ´ JSProxy.proxy.document.body.style.$backgroundColor = '#FF0000';
proxy ãã§ã¤ã³ã®éä¸ã®ã¤ã³ã¹ã¿ã³ã¹ããå¼ã³åºããã¨ãåºæ¥ã¾ãã
var location:JSProxy = JSProxy.proxy.location; // location ã®æ å ±ãåå¾ã§ãã var browserUrl:String = location.$href; var hostname:String = location.$hostname; // ä»£å ¥ãåºæ¥ãã以ä¸ã®ä¾ã§ã¯å¥ã®URLã«ç§»åããã location.$href = 'http://www.hatena.ne.jp/';
DOM ã®è¦ç´ ãåå¾ãã¦é åã«å¤ãä»£å ¥ããªã©ã®æä½ãããã£ã½ãæ¸ãã¾ãã
// å ¨ä½ãã P ã¿ã°ãåå¾ var pElements:JSProxy = JSProxy.proxy.document.getElementsByTagName('p'); // ä¸åç®ã® innerHTML ã«ä»£å ¥ãã¦å¤æ´ pElements[0].innerHTML = '1st p'; // ä¸åç®ã® innerHTML ã«ä»£å ¥ãã¦å¤æ´ pElements[1].innerHTML = '2nd p';
ãã©ã¼ã ã«é©å½ã«å¤ãå ¥åã㦠submit ãªã©ãå¯è½ã§ãã
<form action="/" id="testform"> <input type="input" value="yuichi" name="username"> <input type="input" value="[email protected]" name="email"> <input type="submit"> </form>
ãªãã©ã¼ã ãªã
var form:JSProxy = JSProxy.proxy.document.getElementById('testform'); var inputs:JSProxy = form.getElementsByTagName('input'); inputs[0].value = 'oreore'; inputs[1].value = '[email protected]'; form.forceAsync = true; // å¾è¿° form.$submit();
ãªæãã§ã§ãã¾ãã
ExternalInterface ã®å¼ã³åºãã¿ã¤ãã³ã°
location.href ã«ä»£å ¥ã form.submit() ã®å¼ã³åºããªã©ãä¸é¨ã®ãã©ã¦ã¶çµã¿è¾¼ã¿ã®ãªãã¸ã§ã¯ããããããã£ã« ExternalInterface ããé¢æ°å¼ã³åºããããããå¤ã®ã»ãããè¡ãã¨ãã¿ã¤ãã³ã°ã«ãã£ã¦ Flash ã® IOError ãçºçããFlash å´ããã§ã¯åé¿ã§ãã¾ããããã®ããå¤ã setTimeout ããããã§ãã»ãã¿ã¼ã®ã³ã¼ãã¯
(function(_0) {setTimeout(function(){try{location.href = _0}catch(e){};}, 0);})
ã®ããã«å¼ã³åºãã¦ãã¾ããã»ãã¿ã¼ã¯æ»ãå¤ãåå¾ããå¿ è¦ãç¡ããããããªåé¿æ¹æ³ã§åé¡ç¡ãã®ã§ãããé¢æ°å¼ã³åºãã¯ãããè¡ãã¾ããããããæ»ãå¤ãå¥ã«ãã£ã¦ãç¡ãã¦ãåé¡ãªãé¢æ°ããããã(form.submit() ãªã©ããã§ãã)ãforceAsync ã true ã«è¨å®ãã㨠setTimeout(function() {}, 0) ã使ã£ãé¢æ°å¼ã³åºãã¸ã¨å¼·å¶çã«å¤æ´ã§ãã¾ãã
ãã®ä» ExternalInterface ã®å¼ã³åºãå¨ãã® BK ã JSProxy.as ã«çµæ§ã¤ã¾ã£ã¦ãã®ã§ãExternalInterface ã«èå³ã®ããæ¹ã¯åèã«ãªãããããã¾ããã