JS AS / Shibuya.js in Kyoto
æ¬æ¥ã® OSC Kansaia 2008 ã§éããã Shibuya.js in Kyoto ã§ãJavaScript 㨠ActionScript ã®é£æºã«ã¤ãã¦è©±ãã¾ãããé¢è¥¿ã®ã«ã³ãã¡ã¬ã³ã¹ã§ã®çºè¡¨ã¯åãã¦ã§ãããã楽ããã£ãã§ããã¹ãã¼ã«ã®çãããåå ãããçãããã©ãããããã¨ããããã¾ããã¼ã
以ä¸çºè¡¨è³æã§ãã
JS <-> AS
- JavaScript 㨠ActionScript ã®é£æº
èªå·±ç´¹ä»
- ã¯ã¦ãªã¨ã³ã¸ãã¢
- èé ç¥ä¸ (id:secondlife)
- Ruby, ActionScript3, JavaScript
JS 㨠AS
- JS ã ãã§ãããªãï¼
- AS ã ãã§ãããªãï¼
- ç¸äºã«è£å®ããããé¢ä¿
- 両æ¹ä½¿ããã¨ãæ§ã ãªã¡ãªããã
JavaScript -> ActionScript
- crossdomain.xml, domain è¶ ã
- ãã¡ã¤ã«ã®è¤æ°é¸æã«ããåæã¢ãããã¼ã
- swfupload ( http://swfupload.org/ )
- ãã¤ããªæä½
JavaScript -> ActionScript
- ãã«ãã¡ãã£ã¢é¢é£
- ãµãã ããªFlashPlayerAPI
- html ç»åã®ãªã¢ã«ã¿ã¤ã å å·¥
- ã¢ã³ãã¨ã¤ãªã¢ã¹ãã©ã³ãã§æç»
- AS ã©ã¤ãã©ãªã®å©ç¨
ActionScript -> JavaScript
- URL ã®å¤æ´
- location.query, location.hash
- JS ã® API ã§ã®æ
å ±åå¾
- navigator.userAgent
ActionScript -> JavaScript
- html ã®è¦ç´ åå¾
- ããã°ãã¼ãçã§ãããã°ã®æ¬æçã®æ å ±å©ç¨
- html ä¸ã«åçãªã¼ãã¼ã¬ã¤, ã¹ã¯ãã¼ã«å¶å¾¡
- ã¯ã¦âã¹ã¿
- http://d.hatena.ne.jp/secondlife/20070913/1189691401
JS <-> AS ã® API
- ExternalInterface
- ExternalInterface#addCallback
- JavaScript ããå¼ã³åºãã API ãç»é²
- ExternalInterface#call
- JavaScript ãå¼ã³åºã
- ExternalInterface#addCallback
ExternalInterface# addCallback
JS å´ãã
$('flash_id').example(arg);
ã§ç°¡åã«å¼ã³åºããï¼ãã©åé¡ãâ¦
- é¢æ°å¼ã³åºãæãswf ããã¼ããçµãã£ã¦ãªãã¨ã¨ã©ã¼
- Flash å´ã§ã®éåæå¦ç
- JS ã«ã©ããã£ã¦éç¥ããã
swf æªãã¼ãåé¡
- swf ãã¼ãå®äºæã«ãExternalInterface#call 㧠JS å´ã«éç¥
MyApp.onLoad = function() { MyApp.example(arg); };
// AS å é¨ã§ãã¼ããçµãã£ããéç¥ ExternalInterface. call('MyApp.onLoad');
Flash å´ã§ã®éåæå¦ç
- ãããã¯ã¼ã¯ä¸ã®ãã¡ã¤ã«ããã¼ããçµãã£ãããçã®å¦ç
- Flash å´ã®éåæå¦çå®äºæãã¦ãã¼ã¯ãªIDã§é¢æ°ãå¼ã¶
// AS å¦çå®äºæ ExternalInterface. call('MyApp.exampleCallback', uniq_id, data);
- é常㯠JS å´ã§ Object ãä½ã£ã¦å¦çãã©ãã
- 使ãããã API ã«
ExternalInterface#call
- JavaScript ã®é¢æ°å¼ã³åºã
ExternalInterface. call('MyApp.exampleCallback', uniq_id, data);
ExternalInterface#call åé¡ç¹
-
- 'Foo.bar.baz' ãªé¢æ°ã®ã¿
- 'Foo.bar().baz' ãªã©ã®å¼ã³åºãã¯ä¸å¯
- JS ã®å¤æ°ã¸ã®ä»£å ¥ãåç §ãä¸å¯
- ExternalInterface. call('document.body.innerHTML'); // ã¨ã©ã¼
- 'Foo.bar.baz' ãªé¢æ°ã®ã¿
ExternalInterface#call
ã¯ãã¼ã¸ã£ãªæååã§æ¸¡ãã¨ä½ã§ãå¯è½
# JS ã®å¤æ°ã®åç § var body:String = ExternalInterface.call('(function() { return document.body.innerHTML; })');
# JS ã®å¤æ°ã¸ä»£å ¥ ExternalInterface.call('(function(arg) { document.body.innerHTML = arg; })', 'hello');
ExternalInterface#call BK ãã®ä»
- ãã®ä» JS å¼ã³åºãã® BK ããããã
- http://github.com/hotchpotch/as3rails2u/tree/master/src/com/rails2u/utils/JSUtil.as
ExternalInterface#call
è¤éãªå¼ã³åºãã«ãªãã¨å¤§å¤
- ããã§â¦
JSProxy
ExternalInterface#call ã®é¢åãªå¦çããããªã«ãã¦ããã
var body:String = JSProxy.proxy.document.body.$innerHTML; JSProxy.proxy.document.body.$innerHTML = 'hello';
JSProxy - Example
var location:JSProxy = JSProxy.proxy.location; // location ã®æ å ±ãåå¾ã§ãã var browserUrl:String = location.$href; var hostname:String = location.$hostname; location.$href = 'http://www.hatena.ne.jp/';
JSProxy - HTML ãã©ã¼ã ã®éä¿¡
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();
JSProxy
- ç¶ã㯠Web ã§ï¼
- JSProxy ã使ã㨠AS -> JS ã¯æ¥½ã«
- JS -> AS ã楽ã«ããã
Uffy
- http://github.com/hotchpotch/uffy/tree/master
- AS ããç°¡åã« JS ã®ã¯ã©ã¹ä½æã»ã¡ã½ããå®ç¾©
- ä»ã¾ã§ã¯ã©ããããã¡ãã¡æ¸ãã¦ãã
- Uffy ã使ãã¨ãç¬èªã©ããå®ç¾©ããªãã¦ãï½
Uffy.as
import uffy.javascript; public class URI { javascript function getURL(...) javascript function postURL(...)
import uffy.Uffy; Uffy.register('URI', URI);
Uffy.js
var uffy = new Uffy('GetURL.swf'); uffy.load('URI', function(URI) { var uri = new URI; uri.getURL(fooUrl, callbackFunc); }); // å¥ã®ã register ãã¦ããã¨ããã¤ã uffy.load('Exif', function(Exif) { var uri = new Exif(url); exif.load(callbackFunc); });
no Uffy.js
JS å´ã¯ Uffy.js 使ããªãã¦ã OK
var uri = new $('my_swf_id').URI; uri.getURL(fooUrl, callbackFunc); var exif = new $('my_swf_id').Exif(url); exif.load(callbackFunc);
Uffy help
- èªå㧠help å¤æ°ãç»é²ããã
alert($('my_swf_id').UffyTest.help);
- help å¤æ°ã¯ãå®ç¾©ãããé¢æ°ã®å¼æ°ãæ»ãå¤ã表示
callFunc(**, Function):** refrect():** foo():String
Uffy
- 1swf ã® id ã«è¤æ°ã® JS ã®ã¯ã©ã¹ãæã¦ã
- javascript namespace ã«ããé¢æ°ç»é²
- AS å´ã¯ãAS ã®ã¯ã©ã¹ãæ¸ãããã« JS ã®ã¯ã©ã¹ãå®ç¾©
- help ã®è¡¨ç¤º
- Uffy.js ã使ã£ã swf ãã¼ãå¾ ã¡
- ãã®ä»â¦
ã¾ã¨ã
- JS <-> AS ã¯ç¸äºã«è£å®ããããé¢ä¿
- AS ã§ã§ããªããã©ã¦ã¶æä½ã JS çµç±ã§
- JSProxy 使ãã¨ä¾¿å©ï¼
- JS ã§ã§ããªããã¨ãé£ãããã¨ã AS ã«
- Uffy 使ãã¨ä¾¿å©ï¼