ã³ãã³ãã©ã¤ã³ã®Flashéçºç°å¢ãæ´ãã
HTML5ã¸ã®æµããå éãã¦ããæ¨ä»ã§ããããã®ã¨ããä»äºã®ä¸ã§Flashã«è§¦ãæ©ä¼ãå¤ããªã£ã¦ãã¾ããã
ãã£ãããªã®ã§ãå¿ããªããã¡ã«ActionScriptã«ããFlashéçºç°å¢ãæ´ããæé ãã¡ã¢ãã¦ãããã¨æãã¾ãã
åææ¡ä»¶
ãã¤ã³ãã¯ä»¥ä¸ã®2ã¤ã
- ã³ãã³ãã©ã¤ã³ã§å®çµãããã¨
- ç¡æã§ã§ãããã¨
ãããã«åä½ç¢ºèªã¯ãã©ã¦ã¶ã使ã£ã¦ããã¾ããããã®ä»ã®ä½æ¥ã¯åºæ¬çã«SSHæ¥ç¶ããã¿ã¼ããã«ä¸ã§è¡ãã¾ãã
ãµã¼ã㯠CentOS 5.5 64bitçãã¯ã©ã¤ã¢ã³ã㯠Windows 7 64bitçã§ãããµã¼ãæ©ã«ã¯GUIç°å¢ã¯å ¥ã£ã¦ãã¾ããã
Javaå®è¡ç°å¢ã®æºå
å¾è¿°ããFlex SDKãåä½ãããããã«ãJavaå®è¡ç°å¢(JRE)ãå¿ è¦ã«ãªãã¾ãã
ä¸è¨ãã¼ã¸ãããä»å㯠Linux x64 RPM ããã¦ã³ãã¼ããã以ä¸ã®ã³ãã³ãã§ã¤ã³ã¹ãã¼ã«ãã¾ãã2010å¹´11æ20æ¥ç¾å¨ã®ææ°ç㯠Version 6 Update 22 ã§ããã
$ sudo sh jre-6u22-linux-x64-rpm.bin ... $ which java /usr/bin/java $ java -version java version "1.6.0_22" Java(TM) SE Runtime Environment (build 1.6.0_22-b04) Java HotSpot(TM) 64-Bit Server VM (build 17.1-b03, mixed mode)
ã³ã³ãã¤ã©ã®æºå
ã³ã³ãã¤ã©ã«ã¯Adobeãå ¬éãã¦ãã Flex SDK ãå©ç¨ãã¾ãã
Flex SDKã«ã¯2種é¡ããããªã¼ãã³ã½ã¼ã¹ãããã¯ãã®ã¿ã§æ§æããã Open Source Flex SDK ã¨ãããã«ãªã¼ãã³ã½ã¼ã¹ã§ãªããã®ãå«ãã Free Adobe Flex SDK ãç¨æããã¦ãã¾ããã©ã¡ããç¡æã§ä½¿ããã¨ãã§ãã¾ãã
ä»åèªåãæ³å®ãã¦ããç¨éã§ã¯ãªã¼ãã³ã½ã¼ã¹çã§ç¹ã«ä¸è¶³ã¯ãªãã®ã§ãã©ã¤ã»ã³ã¹ã馴æã¿ã®ããMPLã§ããããªã¼ãã³ã½ã¼ã¹çã使ããã¦ããããã¨ã«ãã¾ããã
ä¸è¨ãã¼ã¸ä¸ã® Open Source Flex 4 SDK ãªã³ã¯ãããã¦ã³ãã¼ãã§ãã¾ãã2010å¹´11æ20æ¥ç¾å¨ã®ææ°ç㯠Flex 4.1 Update Release (4.1.0.16076) ã§ããã
ZIPããã±ã¼ã¸ã«ãªã£ã¦ãã¾ãã®ã§ãé©å½ãªå ´æã«å±éããä¸ã®binãã£ã¬ã¯ããªã«PATHãéãã¦ããã¾ãã
$ unzip flex_sdk_4.1.0.16076_mpl.zip -d ~/flex ... $ echo 'export PATH=$HOME/flex/bin:$PATH' >> ~/.bashrc $ . ~/.bashrc $ which mxmlc ~/flex/bin/mxmlc $ mxmlc -version Version 4.1.0 build 16076
ãµã³ãã«ããã°ã©ã ã®ä½æ
æ©éãªã«ãä½ã£ã¦ã¿ã¾ãã
package { import flash.display.Sprite; import flash.display.Bitmap; import flash.display.BitmapData; import flash.text.TextField; import flash.text.TextFieldAutoSize; import flash.text.TextFormat; import flash.events.Event; [SWF(width="640", height="480", frameRate="30")] public class HelloWorld extends Sprite { private var base:Sprite; public function HelloWorld():void { var txtFld:TextField = new TextField(); txtFld.autoSize = TextFieldAutoSize.LEFT; txtFld.text = 'Hello World!'; var fmt:TextFormat = new TextFormat(); fmt.size = 32; txtFld.setTextFormat(fmt); var bmpData:BitmapData = new BitmapData(txtFld.width, txtFld.height); bmpData.draw(txtFld); var bmp:Bitmap = new Bitmap(bmpData); bmp.smoothing = true; bmp.x = -(bmp.width / 2); bmp.y = -(bmp.height / 2); base = new Sprite(); base.x = 320; base.y = 240; base.addChild(bmp); addChild(base); addEventListener(Event.ENTER_FRAME, onEnterFrame); } private function onEnterFrame(event:Event):void { base.rotationY += 4; } } }
ä¸ã®ã³ã¼ããHelloWorld.asã¨ãããã¡ã¤ã«åã§ä¿åãã以ä¸ã®ã³ãã³ãã§ã³ã³ãã¤ã«ãã¾ãã
$ mxmlc HelloWorld.as
ã³ã³ãã¤ã«ãå®äºããã°ãåããã£ã¬ã¯ããªã«HelloWorld.swfã¨ãããã¡ã¤ã«ãä½æããã¦ãã¾ãããã¨ã¯ããããã©ã¦ã¶ã§èªã¿è¾¼ãã ãã§ãã
ãã£ãããµã¼ãä¸ã§éçºãã¦ããã®ã§ããããã³ã³ããã¨ãªãHTMLãã¡ã¤ã«ãä¸ç·ã«ä½ã*1ããã®ã¾ã¾Apacheçµç±ã§åç §ã§ããããã«ãã¦ãã¾ãã®ã楽ã§ãããã
ã¡ãªã¿ã«ãä¸è¨ã®ãµã³ãã«ã¯åã« "Hello World!" ãå転ããã ãã®ã·ã³ãã«ãªFlashã§ãã
ã³ã³ãã¤ã«ãªãã·ã§ã³
ä¸è¨ã®ã³ãã³ãã§ã³ã³ãã¤ã«ããã¨è¦åã¡ãã»ã¼ã¸ãåºã¾ããããã㯠-static-link-runtime-shared-libraries ãªãã·ã§ã³ãä»ãããã¨ã§åé¿ã§ãã¾ãã
$ mxmlc -static-link-runtime-shared-libraries HelloWorld.as
ã³ã³ãã¤ã«ãªãã·ã§ã³ã¯ãä¸è¨ã®ããã«ã³ãã³ãã©ã¤ã³ããæå®ããä»ã«ãè¨å®ãã¡ã¤ã«ã«æ¸ãã¦ãããã¨ãã§ãã¾ãã
è¨å®ãã¡ã¤ã«ã«ã¯ã${FLEX_ROOT}/frameworks/flex-config.xml ã«é ç½®ããã¦ããå ±éè¨å®ãã¡ã¤ã«ã¨ãã³ã³ãã¤ã«å¯¾è±¡ãã¡ã¤ã«ãã¨ã®ãã¼ã«ã«è¨å®ãã¡ã¤ã«ãããã¾ãã
ãã¼ã«ã«è¨å®ãã¡ã¤ã«ã¯ãã³ã³ãã¤ã«å¯¾è±¡ã®ASãã¡ã¤ã«ã¨åããã£ã¬ã¯ããªã« -config.xml ãµãã£ãã¯ã¹ãã¤ãã¦ç½®ãã¦ããã¾ããä¾ãã°å ç¨ã® HelloWorld.as ã®å ´åãHelloWorld-config.xml ã¨ãããã¡ã¤ã«ãåããã£ã¬ã¯ããªã«ç½®ãã¦ããã¨ãã³ã³ãã¤ã«æã«ç¹ã«æå®ãããªãã¦ãèªã¿è¾¼ãã§ããã¾ãã
ä»ã«ããload-config ãªãã·ã§ã³ã«ãã£ã¦æ示çã«è¨å®ãã¡ã¤ã«ãæå®ãããã¨ãã§ãã¾ãã
è¨å®ãã¡ã¤ã«ã®ãã©ã¼ãããã¯ãä¸çªåç´ãªå½¢ã ã¨ä»¥ä¸ã®ããã«ãªãã¾ãã
<?xml version="1.0" encoding="UTF-8"?> <flex-config> <static-link-runtime-shared-libraries>true</static-link-runtime-shared-libraries> </flex-config>
ãªãã·ã§ã³æå®ã®åªå 度ã¯ãã³ãã³ãã©ã¤ã³ãªãã·ã§ã³ ï¼ load-config ã§æå®ããè¨å®ãã¡ã¤ã« ï¼ ãã¼ã«ã«è¨å®ãã¡ã¤ã« ï¼ flex-config.xmlãã¨ãªã£ã¦ãã¾ãã
ãªãã·ã§ã³ã®ç°¡åãªãªã¹ãã¯ä»¥ä¸ã®ã³ãã³ãã§ç¢ºèªã§ãã¾ãã
$ mxmlc -help advanced list details
Makefile
é »ç¹ã«ã³ã³ãã¤ã«ãè¡ãå ´åãmake ã ant ãªã©ã®ãã«ããã¼ã«ã使ããã¨ã«ãªããã¨æãã¾ããèªåã¯ä½¿ãæ £ãã make ãå©ç¨ãã¦ãã¾ãã
ã·ã³ãã«ãªswfçæç¨Makefileã¯ä»¥ä¸ã®ãããªå½¢ã«ãªãã¾ãã
MXMLC = mxmlc MXMLCFLAGS = TARGETS = HelloWorld.swf all: $(TARGETS) clean: $(RM) $(TARGETS) .SUFFIXES: .as .swf .as.swf: $(MXMLC) $(MXMLCFLAGS) $<
traceãã°ã®åºå
ãããã°çã® Flash Player ã§ã¯ trace() é¢æ°ã使ã£ã¦ãã¡ã¤ã«ã¸ã®ãã°åºåãè¡ããã¨ãã§ãã¾ãã
ä¸è¨ãã¼ã¸ãããããã°çãã¬ã¤ã¤ã¼ããã¦ã³ãã¼ããã¦ã¤ã³ã¹ãã¼ã«ãã¾ãã
ã¹ã¿ã³ãã¢ãã³çãããã¾ãããFirebugã¨çµã¿åããã¦ä½¿ããã¨ä¾¿å©ãªã®ã§ãèªåã¯ä¸è¨ãã¼ã¸ä¸ã® "Windows Flash Player 10.1 Plugin content debugger (for Netscape-compatible browsers)" ãã¤ã³ã¹ãã¼ã«ãã¦Firefoxã§åããã¦ãã¾ãã*2
次㫠mm.cfg ãã¡ã¤ã«ã«ä»¥ä¸ã®è¨å®ãå ãã¾ãããã¡ã¤ã«ãç¡ããã°æ°è¦ä½æãã¾ãã
ErrorReportingEnable=1 TraceOutputFileEnable=1
mm.cfg ãã¡ã¤ã«ã¨ trace() é¢æ°ããã®åºåãè¨é²ããããã°ãã¡ã¤ã«ã®å ´æã¯ä»¥ä¸ã®ãã¼ã¸ãåç §ãã¦ãã ãããWindows 7 ã®å ´å㯠Windows Vista ã¨åãå ´æã«é ç½®ããã¦ãã¾ãã
trace() é¢æ°ã«ãããã°åºåãæå¹ã«ããã«ã¯ãswfãdebugãã©ã°ä»ãã§ã³ã³ãã¤ã«ããå¿ è¦ãããã¾ãã
è¨å®ãã¡ã¤ã«ã§æå®ããå ´åã¯ä»¥ä¸ã®ããã«ãªãã¾ãã
<?xml version="1.0" encoding="UTF-8"?> <flex-config> <compiler> <debug>true</debug> </compiler> <static-link-runtime-shared-libraries>true</static-link-runtime-shared-libraries> </flex-config>
JavaScriptã³ã³ã½ã¼ã«ã¸ã®ãã°åºå
ã¾ãã¯ãã£ã¨ç°¡åã« console.log() ã使ã£ã¦FirebugãGoogle Chromeã®JavaScriptã³ã³ã½ã¼ã«ã«ã¡ãã»ã¼ã¸ãåºåãããã¨ãã§ãã¾ãã
ActionScriptããJavaScriptãå¼ã³åºãã«ã¯ ExternalInterface ã¯ã©ã¹ã使ãã¾ãã以ä¸ã®ãããªã¡ã½ãããã©ããã«å®ç¾©ãã¦ããã¨ä¾¿å©ãã¨æãã¾ãã
import flash.external.ExternalInterface; public function log(message:Object):void { ExternalInterface.call('console.log', message.toString()); }
ãã㧠log() ã¡ã½ããã«æ¸¡ããå¼æ°ãFirebugãGoogle Chromeã®JavaScriptã³ã³ã½ã¼ã«ã«è¡¨ç¤ºããã¾ãã
fdbã«ãããªã¢ã¼ããããã°
ãã£ã¨æ¬æ ¼çãªãããã°ã«ã¯ActionScriptã®ãããã¬ã§ãã fdb ãå©ç¨ã§ãã¾ããfdb 㯠Flex SDK ã«å梱ããã¦ãã¾ãã
éçºç°å¢ã¨å®è¡ç°å¢ãåä¸ãã¹ãã§ãããã¿ã¼ã³ããã£ã¨ãã·ã³ãã«ãªã®ã§ãããä»åã¯fdbããµã¼ãä¸ã§ããã¬ã¤ã¤ã¼ãã¯ã©ã¤ã¢ã³ãä¸ã§åä½ãããç¶æ ã§ãããã°ãè¡ãã¾ãã
ã¾ããtraceãã°åºåã®éã«è¡ã£ãããã«ãdebugãã©ã°ä»ãã§swfãã³ã³ãã¤ã«ããã¯ã©ã¤ã¢ã³ãä¸ã®ãããã°çãã¬ã¤ã¤ã¼ã§èµ·åãã¾ãã
次ã«ãµã¼ãä¸ã§ä»¥ä¸ã®ã³ãã³ããå®è¡ããfdbãæ¥ç¶å¾ ã¡åãç¶æ ã«ãã¾ãã
$ fdb Adobe fdb (Flash Player Debugger) [ãã«ã 16076] Copyright (c) 2004-2007 Adobe, Inc. All rights reserved. (fdb) run Player ãæ¥ç¶ããã®ãå¾ ã£ã¦ãã¾ã
ã¯ã©ã¤ã¢ã³ãä¸ã®ãããã°çãã¬ã¤ã¤ã¼ãå³ã¯ãªãã¯ããã¡ãã¥ã¼ä¸ã®ããããã¬ã¼ããã¯ãªãã¯ãã¦ããã«ã表示ãæ¥ç¶å ã«ãã»ãã®ã³ã³ãã¥ã¼ã¿ã¼ããé¸ãã§ãµã¼ãã®IPã¢ãã¬ã¹ãå ¥åãã¾ãã
ãæ¥ç¶ããããé¸æããã¨ããããã°çãã¬ã¤ã¤ã¼ãå¾ ã¡åãç¶æ ã®fdbã«æ¥ç¶ãããããã°ã»ãã·ã§ã³ãéå§ãããfdbã«ãããããã°ãå¯è½ãªç¶æ ã«ãªãã¾ãã
ãªãããã®éããµã¼ãã¯ã¯ã©ã¤ã¢ã³ãã«å¯¾ã㦠TCP/7935 ã®ãã¼ããéãã¦ããå¿ è¦ãããã¾ãã
$ fdb Adobe fdb (Flash Player Debugger) [ãã«ã 16076] Copyright (c) 2004-2007 Adobe, Inc. All rights reserved. (fdb) run Player ãæ¥ç¶ããã®ãå¾ ã£ã¦ãã¾ã Player ãæ¥ç¶ããã¾ãããã»ãã·ã§ã³ãéå§ãã¦ãã¾ãã ãã¬ã¼ã¯ãã¤ã³ããè¨å®ãã¦ãcontinueãã¨å ¥åããã»ãã·ã§ã³ãåéãã¦ãã ããã [SWF] /sample/HelloWorld.swf - 2,287 ãã¤ã (解åå¾) (fdb)
å¦çã®æåãããããã°ãè¡ãªãããå ´åãã»ãã·ã§ã³ãéå§ããç¶æ ã§ãããã°çãã¬ã¤ã¤ã¼ãåä½ãã¦ãããã¼ã¸ãåèªã¿è¾¼ã¿ããã°OKã§ãã
fdbã«ãããããã°ã®è©³ç´°ã¯ä»¥ä¸ã®ãã¼ã¸ãåèã«ãªãã¾ãã
ãã®ä»
ãã¨ã¯ãªãã¡ã¬ã³ã¹ããã®ä»è³æãåèã«ããªããéçºãé²ãã¦ããã¾ãããªãã¡ã¬ã³ã¹ã«ã¯æ§ã ãªããã±ã¼ã¸ãè¨è¼ããã¦ãã¾ãããFlex SDK ã§å©ç¨å¯è½ãªã®ã¯ flash, mx, spark ã®3ã¤ã®ããã±ã¼ã¸ã ãã§ãã®ã§æ³¨æãã¦ãã ããã
ä»ã«Flashãéçºãã¦ããä¸ã§è©°ã¾ããããããªã®ã¯ãã¯ãã¹ãã¡ã¤ã³ããªã·ã¼ã¾ããã§ããããã
Flashã§ã¯ãã¹ãã¡ã¤ã³ã®éä¿¡ãè¡ãå ´åãéä¿¡å ã®ãµã¼ãã«ã¯ãã¹ãã¡ã¤ã³ããªã·ã¼ãã¡ã¤ã« "crossdomain.xml" ãè¨ç½®ããã¦ããããã¤é©åãªè¨å®ããªããã¦ããå¿ è¦ãããã¾ãããã㯠URLLoader/URLRequest ã®ãããªåçºãªã¯ã¨ã¹ãã®å ´åããSocket/XMLSocket ã®ãããªæç¶çæ¥ç¶ã®ãããªå ´åãåæ§ã§ãã
Flashéçºã¯ã¾ã ã¾ã 触ãå§ããã°ããã§æ £ãã¦ãã¾ããããã¼ã¡ã¼ã¡è²ã 試ãã¦ãããã¨æãã¾ãã