<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>RichMedia+ &#187; ActionScript3</title>
	<atom:link href="http://blog.richmediaplus.com/tag/actionscript3/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.richmediaplus.com</link>
	<description>About the Adobe&#039;s RIA related solution and technology, like Adobe Air, Adobe Flex, Mobile Dev. You also can find the SEO for Flex, RIA, User Ex in this blog.</description>
	<lastBuildDate>Fri, 16 Dec 2011 09:33:27 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Flex SDK Security Update</title>
		<link>http://blog.richmediaplus.com/2011/12/flex-sdk-security-update/</link>
		<comments>http://blog.richmediaplus.com/2011/12/flex-sdk-security-update/#comments</comments>
		<pubDate>Fri, 02 Dec 2011 10:27:20 +0000</pubDate>
		<dc:creator>Ticore Shih</dc:creator>
				<category><![CDATA[ActionScript3]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[Security]]></category>

		<guid isPermaLink="false">http://blog.richmediaplus.com/?p=902</guid>
		<description><![CDATA[昨天突然看到 Flex SDK 居然大幅度發布安全性更新 不是都要捐給 Apache 了嗎? 從 3.0.0 一路到 4.5.1 全部都有更新 而最新的 4.6 則不受影響，可以參考以下文章 Security update available for Adobe Flex SDK (APSB11-25) Flex Security Issue APSB11-25 只要版號後面加上 A 的都是安全更新過的，e.g. Flex 4.5.1.21328A 另外 Adobe 也提供了補救工具 APSB11_25_Patch_Tool.air 可以直接對既有的 SWF 進行偵測並修復 詳細使用請參考上面連結說明 很好奇動作這麼大，到底是什麼樣的漏洞? 根據文件說明找了原始碼 mx.modules.ModuleManager.as 內的 inner class ModuleInfo 的 load() function public function load(applicationDomain:ApplicationDomain = null, [...]
Related posts:<ol>
<li><a href='http://blog.richmediaplus.com/2011/05/flex-style-module/' rel='bookmark' title='Flex 4 Style Module'>Flex 4 Style Module</a></li>
<li><a href='http://blog.richmediaplus.com/2011/11/direct-referenced-module-issue/' rel='bookmark' title='Flex App 直接引用外部 Module 的問題'>Flex App 直接引用外部 Module 的問題</a></li>
<li><a href='http://blog.richmediaplus.com/2009/03/tour-de-flex-update/' rel='bookmark' title='Tour de Flex update to Version 1.2!'>Tour de Flex update to Version 1.2!</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>昨天突然看到 Flex SDK 居然大幅度發布安全性更新<br />
不是都要捐給 Apache 了嗎?<br />
從 3.0.0 一路到 4.5.1 全部都有更新<br />
而最新的 4.6 則不受影響，可以參考以下文章</p>
<p><a href="http://blogs.adobe.com/psirt/2011/11/security-update-available-for-adobe-flex-sdk-apsb11-25.html">Security update available for Adobe Flex SDK (APSB11-25)</a><br />
<a href="http://kb2.adobe.com/cps/915/cpsid_91544.html">Flex Security Issue APSB11-25</a></p>
<p>只要版號後面加上 A 的都是安全更新過的，e.g. Flex 4.5.1.21328A<br />
另外 Adobe 也提供了補救工具 <a href="http://kb2.adobe.com/cps/915/cpsid_91544/attachments/APSB11_25_Patch_Tool.air">APSB11_25_Patch_Tool.air</a><br />
可以直接對既有的 SWF 進行偵測並修復<br />
詳細使用請參考上面連結說明</p>
<p>很好奇動作這麼大，到底是什麼樣的漏洞?<br />
根據文件說明找了原始碼 mx.modules.ModuleManager.as<br />
內的 inner class ModuleInfo 的 load() function</p>
<pre>  public function load(applicationDomain:ApplicationDomain = null,
                       securityDomain:SecurityDomain = null,
                       bytes:ByteArray = null,
                       moduleFactory:IFlexModuleFactory = null):void</pre>
<p>Flex SDK 4.5.1，在 ModuleManager.as 的 463 行<br />
原本是這樣</p>
<pre>      c.securityDomain = securityDomain;
      if (securityDomain == null &#038;&#038; Security.sandboxType == Security.REMOTE)
          c.securityDomain = SecurityDomain.currentDomain;</pre>
<p>安全更新後變成這樣</p>
<pre>      // setting securityDomain is not allowed on non-REMOTE sandboxes
      if (securityDomain != null &#038;&#038; Security.sandboxType == Security.REMOTE)
          c.securityDomain = securityDomain;</pre>
<p>簡單講就是「對於非 REMOTE 沙箱應用，不允許設定外部 Module 的 securityDomain」</p>
<p>好像對企業用戶本地端 App 才有影響吧<br />
至今做過的應用幾乎全部跑在網頁上，連 Module 都很少用到<br />
無法感受到這有多嚴重&#8230;</p>
<p>Related posts:<ol>
<li><a href='http://blog.richmediaplus.com/2011/05/flex-style-module/' rel='bookmark' title='Flex 4 Style Module'>Flex 4 Style Module</a></li>
<li><a href='http://blog.richmediaplus.com/2011/11/direct-referenced-module-issue/' rel='bookmark' title='Flex App 直接引用外部 Module 的問題'>Flex App 直接引用外部 Module 的問題</a></li>
<li><a href='http://blog.richmediaplus.com/2009/03/tour-de-flex-update/' rel='bookmark' title='Tour de Flex update to Version 1.2!'>Tour de Flex update to Version 1.2!</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://blog.richmediaplus.com/2011/12/flex-sdk-security-update/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>自訂 Flex 滑鼠游標實體</title>
		<link>http://blog.richmediaplus.com/2011/11/custom-flex-cursor-instance/</link>
		<comments>http://blog.richmediaplus.com/2011/11/custom-flex-cursor-instance/#comments</comments>
		<pubDate>Sat, 05 Nov 2011 02:48:09 +0000</pubDate>
		<dc:creator>Ticore Shih</dc:creator>
				<category><![CDATA[ActionScript3]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[Adobe Flex]]></category>
		<category><![CDATA[Cursor]]></category>

		<guid isPermaLink="false">http://blog.richmediaplus.com/?p=878</guid>
		<description><![CDATA[遇到一個問題是，想要自訂 Flex App 的 Cursor 可是又要能存取 Cursor 實體 以便做其他的動態控制 可是 Flex CursorManager 基本上是不允許這樣做的 只能以 Class 方式設定 Cursor，也無法存取到目前 Cursor 實體 網路上有人提過解決方式 Jesse Warden &#8211; Making a Cooler Cursor in Flex 可是他是藉由 Hack CursorManager 方式做到 實際用 Flex 4.5 測試，發現只要將編譯模式從 Merged into code 改為 RSL 這個方法就失效了，只好自行另外想辦法 觀察 StyleManager 實作，發現 Cursor 實體是放在 systemManager.cursorChildren > cursorHolder 內 於是想到可以自行指定空的 Sprite 作為 [...]
Related posts:<ol>
<li><a href='http://blog.richmediaplus.com/2011/08/mxmlc-define-embed-source/' rel='bookmark' title='Flex Compiler 編譯參數嵌入外部資源技巧'>Flex Compiler 編譯參數嵌入外部資源技巧</a></li>
<li><a href='http://blog.richmediaplus.com/2011/06/flex-spark-preloader-disappear/' rel='bookmark' title='解決 Flex 4.x 下載進度不出現的問題'>解決 Flex 4.x 下載進度不出現的問題</a></li>
<li><a href='http://blog.richmediaplus.com/2011/10/secureswf-sub-appdomain-issue/' rel='bookmark' title='SecureSWF 與外部模組的陷阱'>SecureSWF 與外部模組的陷阱</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>遇到一個問題是，想要自訂 Flex App 的 Cursor 可是又要能存取 Cursor 實體<br />
以便做其他的動態控制<br />
可是 <a href="http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/mx/managers/CursorManager.html">Flex CursorManager</a> 基本上是不允許這樣做的<br />
只能以 Class 方式設定 Cursor，也無法存取到目前 Cursor 實體<br />
網路上有人提過解決方式 <a href="http://jessewarden.com/2009/01/making-a-cooler-cursor-in-flex.html">Jesse Warden &#8211; Making a Cooler Cursor in Flex</a><br />
可是他是藉由 Hack CursorManager 方式做到<br />
實際用 Flex 4.5 測試，發現只要將編譯模式從 Merged into code 改為 RSL<br />
這個方法就失效了，只好自行另外想辦法</p>
<p>觀察 StyleManager 實作，發現 Cursor 實體是放在 systemManager.cursorChildren > cursorHolder 內<br />
於是想到可以自行指定空的 Sprite 作為 Cursor，然後自行取出 Cursor 實體<br />
另外再加以控制</p>
<p>CustomCursorPanel1.mxml</p>

<div class="wp_syntax"><div class="code"><pre class="mxml" style="font-family:monospace;"><span style="color: #000000;">&lt;?xml version=<span style="color: #ff0000;">&quot;1.0&quot;</span> encoding=<span style="color: #ff0000;">&quot;utf-8&quot;</span>?<span style="color: #7400FF;">&gt;</span></span>
<span style="color: #000000;"><span style="color: #7400FF;">&lt;s:Panel</span> xmlns:fx=<span style="color: #ff0000;">&quot;http://ns.adobe.com/mxml/2009&quot;</span></span>
<span style="color: #000000;">  xmlns:s=<span style="color: #ff0000;">&quot;library://ns.adobe.com/flex/spark&quot;</span></span>
<span style="color: #000000;">  xmlns:mx=<span style="color: #ff0000;">&quot;library://ns.adobe.com/flex/mx&quot;</span></span>
<span style="color: #000000;">  width=<span style="color: #ff0000;">&quot;400&quot;</span> height=<span style="color: #ff0000;">&quot;300&quot;</span> title=<span style="color: #ff0000;">&quot;Custom Cursor Panel 1&quot;</span></span>
<span style="color: #000000;">  rollOver=<span style="color: #ff0000;">&quot;onRollOverHandler(event);&quot;</span></span>
<span style="color: #000000;">  rollOut=<span style="color: #ff0000;">&quot;onRollOutHandler(event);&quot;</span><span style="color: #7400FF;">&gt;</span></span>
 <span style="color: #000000;"><span style="color: #7400FF;">&lt;fx:Declarations</span><span style="color: #7400FF;">&gt;</span></span>
  <span style="color: #000000;"><span style="color: #7400FF;">&lt;flash:TextField</span> id=<span style="color: #ff0000;">&quot;cursorTxt&quot;</span> xmlns:flash=<span style="color: #ff0000;">&quot;flash.text.*&quot;</span> border=<span style="color: #ff0000;">&quot;true&quot;</span> autoSize=<span style="color: #ff0000;">&quot;left&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
 <span style="color: #000000;"><span style="color: #7400FF;">&lt;/fx:Declarations</span><span style="color: #7400FF;">&gt;</span></span>
 <span style="color: #000000;"><span style="color: #7400FF;">&lt;fx:Script</span><span style="color: #7400FF;">&gt;</span></span>
  <span style="color: #000000;">&lt;!<span style="color: #66cc66;">&#91;</span>CDATA<span style="color: #66cc66;">&#91;</span></span>
<span style="color: #000000;">   import mx.core.IChildList;</span>
&nbsp;
<span style="color: #000000;">   protected var cursorID:int;</span>
&nbsp;
<span style="color: #000000;">   public function onRollOverHandler<span style="color: #66cc66;">&#40;</span>e:MouseEvent<span style="color: #66cc66;">&#41;</span>:void<span style="color: #66cc66;">&#123;</span></span>
<span style="color: #000000;">    cursorID = cursorManager.setCursor<span style="color: #66cc66;">&#40;</span>Sprite<span style="color: #66cc66;">&#41;</span>;</span>
&nbsp;
<span style="color: #000000;">    var cursorChildren:IChildList = systemManager.cursorChildren;</span>
<span style="color: #000000;">    if <span style="color: #66cc66;">&#40;</span>!cursorChildren<span style="color: #66cc66;">&#41;</span> return;</span>
<span style="color: #000000;">    var cursorHolder:Sprite = cursorChildren.getChildByName<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;cursorHolder&quot;</span><span style="color: #66cc66;">&#41;</span> as Sprite;</span>
<span style="color: #000000;">    if <span style="color: #66cc66;">&#40;</span>!cursorHolder || !cursorHolder.numChildren<span style="color: #66cc66;">&#41;</span> return;</span>
<span style="color: #000000;">    var cursor:Sprite = cursorHolder.getChildAt<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span> as Sprite;</span>
<span style="color: #000000;">    if <span style="color: #66cc66;">&#40;</span>!cursor<span style="color: #66cc66;">&#41;</span> return;</span>
<span style="color: #000000;">    cursor.addChildAt<span style="color: #66cc66;">&#40;</span>cursorTxt, <span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span>;</span>
&nbsp;
<span style="color: #000000;">    addEventListener<span style="color: #66cc66;">&#40;</span>MouseEvent.MOUSE_MOVE, onMouseEventHandler<span style="color: #66cc66;">&#41;</span>;</span>
<span style="color: #000000;">    addEventListener<span style="color: #66cc66;">&#40;</span>MouseEvent.MOUSE_DOWN, onMouseEventHandler<span style="color: #66cc66;">&#41;</span>;</span>
<span style="color: #000000;">    addEventListener<span style="color: #66cc66;">&#40;</span>MouseEvent.MOUSE_UP, onMouseEventHandler<span style="color: #66cc66;">&#41;</span>;</span>
<span style="color: #000000;">   <span style="color: #66cc66;">&#125;</span></span>
&nbsp;
<span style="color: #000000;">   public function onRollOutHandler<span style="color: #66cc66;">&#40;</span>e:MouseEvent<span style="color: #66cc66;">&#41;</span>:void<span style="color: #66cc66;">&#123;</span></span>
<span style="color: #000000;">    cursorManager.removeCursor<span style="color: #66cc66;">&#40;</span>cursorID<span style="color: #66cc66;">&#41;</span>;</span>
<span style="color: #000000;">    removeEventListener<span style="color: #66cc66;">&#40;</span>MouseEvent.MOUSE_MOVE, onMouseEventHandler<span style="color: #66cc66;">&#41;</span>;</span>
<span style="color: #000000;">    removeEventListener<span style="color: #66cc66;">&#40;</span>MouseEvent.MOUSE_DOWN, onMouseEventHandler<span style="color: #66cc66;">&#41;</span>;</span>
<span style="color: #000000;">    removeEventListener<span style="color: #66cc66;">&#40;</span>MouseEvent.MOUSE_UP, onMouseEventHandler<span style="color: #66cc66;">&#41;</span>;</span>
<span style="color: #000000;">   <span style="color: #66cc66;">&#125;</span></span>
&nbsp;
<span style="color: #000000;">   public function onMouseEventHandler<span style="color: #66cc66;">&#40;</span>e:MouseEvent<span style="color: #66cc66;">&#41;</span>:void<span style="color: #66cc66;">&#123;</span></span>
<span style="color: #000000;">    cursorTxt.text = e.type + <span style="color: #ff0000;">&quot; (&quot;</span>+ e.localX + <span style="color: #ff0000;">&quot; : &quot;</span> + e.localY + <span style="color: #ff0000;">&quot;)&quot;</span>;</span>
<span style="color: #000000;">   <span style="color: #66cc66;">&#125;</span></span>
<span style="color: #000000;">  <span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#93;</span><span style="color: #7400FF;">&gt;</span></span>
 <span style="color: #000000;"><span style="color: #7400FF;">&lt;/fx:Script</span><span style="color: #7400FF;">&gt;</span></span>
<span style="color: #000000;"><span style="color: #7400FF;">&lt;/s:Panel</span><span style="color: #7400FF;">&gt;</span></span></pre></div></div>

<p>CustomCursorPanel1 實際範例</p>
<p>
<object width="500" height="400">
<param name="movie" value="http://blog-uploads.richmediaplus.com/2011/11/CustomCursorPanel1.swf"></param>
<param name="quality" value="high"></param>
<param name="wmode" value="window"></param>
<param name="menu" value="false"></param>
<param name="bgcolor" value="#FFFFFF"></param>
<param name="allowScriptAccess" value="always"></param>
<embed type="application/x-shockwave-flash" width="500" height="400" src="http://blog-uploads.richmediaplus.com/2011/11/CustomCursorPanel1.swf" quality="high" bgcolor="#FFFFFF" wmode="window" menu="false" ></embed>
</object>
</p>
<p>不過缺點是萬一 CursorManager 實作方式大改可能就會失效了<br />
所以又想了另一個方式<br />
實做一個 CursorProxy 類別</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #9900cc; font-weight: bold;">package</span> com<span style="color: #000066; font-weight: bold;">.</span>ticore<span style="color: #000066; font-weight: bold;">.</span>utils  <span style="color: #000000;">&#123;</span>
 <span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.display</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">DisplayObject</span><span style="color: #000066; font-weight: bold;">;</span>
 <span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.display</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">Sprite</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
 <span style="color: #3f5fbf;">/**
  * 提供一個 proxy 類別，給 Flex CursorManager 設定 cursor
  * CursorProxy 另外宣告一靜態的 getter/setter 供存取 cursor 實體
  * 每次 CursorProxy 實體被創建時，都會將靜態 cursor 實體加入自己 display list 下
  * 
  * @author Ticore Shih
  */</span>
 <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #9900cc; font-weight: bold;">class</span> CursorProxy <span style="color: #0033ff; font-weight: bold;">extends</span> <span style="color: #004993;">Sprite</span> <span style="color: #000000;">&#123;</span>
&nbsp;
  static <span style="color: #0033ff; font-weight: bold;">protected</span> <span style="color: #6699cc; font-weight: bold;">var</span> _cursor_<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">DisplayObject</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
  static <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> <span style="color: #0033ff; font-weight: bold;">get</span> cursor<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">DisplayObject</span><span style="color: #000000;">&#123;</span>
   <span style="color: #0033ff; font-weight: bold;">return</span> _cursor_<span style="color: #000066; font-weight: bold;">;</span>
  <span style="color: #000000;">&#125;</span>
&nbsp;
  static <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> <span style="color: #0033ff; font-weight: bold;">set</span> cursor<span style="color: #000000;">&#40;</span><span style="color: #004993;">value</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">DisplayObject</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span><span style="color: #000000;">&#123;</span>
   _cursor_ = <span style="color: #004993;">value</span><span style="color: #000066; font-weight: bold;">;</span>
   <span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #000066; font-weight: bold;">!</span>_cursorProxy_<span style="color: #000000;">&#41;</span> <span style="color: #0033ff; font-weight: bold;">return</span><span style="color: #000066; font-weight: bold;">;</span>
   <span style="color: #0033ff; font-weight: bold;">while</span> <span style="color: #000000;">&#40;</span>_cursorProxy_<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">numChildren</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
    _cursorProxy_<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">removeChildAt</span><span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">0</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
   <span style="color: #000000;">&#125;</span>
   _cursorProxy_<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">addChild</span><span style="color: #000000;">&#40;</span>_cursor_<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
  <span style="color: #000000;">&#125;</span>
&nbsp;
&nbsp;
  static <span style="color: #0033ff; font-weight: bold;">protected</span> <span style="color: #6699cc; font-weight: bold;">var</span> _cursorProxy_<span style="color: #000066; font-weight: bold;">:</span>CursorProxy<span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
  <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> CursorProxy<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
   _cursorProxy_ = <span style="color: #0033ff; font-weight: bold;">this</span><span style="color: #000066; font-weight: bold;">;</span>
   <span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>_cursor_<span style="color: #000000;">&#41;</span> _cursorProxy_<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">addChild</span><span style="color: #000000;">&#40;</span>_cursor_<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
  <span style="color: #000000;">&#125;</span>
 <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>使用範例如下 CustomCursorPanel2.mxml</p>

<div class="wp_syntax"><div class="code"><pre class="mxml" style="font-family:monospace;"><span style="color: #000000;">&lt;?xml version=<span style="color: #ff0000;">&quot;1.0&quot;</span> encoding=<span style="color: #ff0000;">&quot;utf-8&quot;</span>?<span style="color: #7400FF;">&gt;</span></span>
<span style="color: #000000;"><span style="color: #7400FF;">&lt;s:Panel</span> xmlns:fx=<span style="color: #ff0000;">&quot;http://ns.adobe.com/mxml/2009&quot;</span></span>
<span style="color: #000000;">  xmlns:s=<span style="color: #ff0000;">&quot;library://ns.adobe.com/flex/spark&quot;</span></span>
<span style="color: #000000;">  xmlns:mx=<span style="color: #ff0000;">&quot;library://ns.adobe.com/flex/mx&quot;</span></span>
<span style="color: #000000;">  width=<span style="color: #ff0000;">&quot;400&quot;</span> height=<span style="color: #ff0000;">&quot;300&quot;</span> title=<span style="color: #ff0000;">&quot;Custom Cursor Panel 1&quot;</span></span>
<span style="color: #000000;">  rollOver=<span style="color: #ff0000;">&quot;onRollOverHandler(event);&quot;</span></span>
<span style="color: #000000;">  rollOut=<span style="color: #ff0000;">&quot;onRollOutHandler(event);&quot;</span><span style="color: #7400FF;">&gt;</span></span>
 <span style="color: #000000;"><span style="color: #7400FF;">&lt;fx:Declarations</span><span style="color: #7400FF;">&gt;</span></span>
  <span style="color: #000000;"><span style="color: #7400FF;">&lt;flash:TextField</span> id=<span style="color: #ff0000;">&quot;cursorTxt&quot;</span> xmlns:flash=<span style="color: #ff0000;">&quot;flash.text.*&quot;</span> border=<span style="color: #ff0000;">&quot;true&quot;</span> autoSize=<span style="color: #ff0000;">&quot;left&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
 <span style="color: #000000;"><span style="color: #7400FF;">&lt;/fx:Declarations</span><span style="color: #7400FF;">&gt;</span></span>
 <span style="color: #000000;"><span style="color: #7400FF;">&lt;fx:Script</span><span style="color: #7400FF;">&gt;</span></span>
  <span style="color: #000000;">&lt;!<span style="color: #66cc66;">&#91;</span>CDATA<span style="color: #66cc66;">&#91;</span></span>
<span style="color: #000000;">   import com.ticore.utils.CursorProxy;</span>
<span style="color: #000000;">   import mx.core.IChildList;</span>
&nbsp;
<span style="color: #000000;">   protected var cursorID:int;</span>
&nbsp;
<span style="color: #000000;">   public function onRollOverHandler<span style="color: #66cc66;">&#40;</span>e:MouseEvent<span style="color: #66cc66;">&#41;</span>:void<span style="color: #66cc66;">&#123;</span></span>
&nbsp;
<span style="color: #000000;">    cursorID = cursorManager.setCursor<span style="color: #66cc66;">&#40;</span>CursorProxy<span style="color: #66cc66;">&#41;</span>;</span>
<span style="color: #000000;">    CursorProxy.cursor = cursorTxt;</span>
<span style="color: #000000;">    addEventListener<span style="color: #66cc66;">&#40;</span>MouseEvent.MOUSE_MOVE, onMouseEventHandler<span style="color: #66cc66;">&#41;</span>;</span>
<span style="color: #000000;">    addEventListener<span style="color: #66cc66;">&#40;</span>MouseEvent.MOUSE_DOWN, onMouseEventHandler<span style="color: #66cc66;">&#41;</span>;</span>
<span style="color: #000000;">    addEventListener<span style="color: #66cc66;">&#40;</span>MouseEvent.MOUSE_UP, onMouseEventHandler<span style="color: #66cc66;">&#41;</span>;</span>
<span style="color: #000000;">   <span style="color: #66cc66;">&#125;</span></span>
&nbsp;
<span style="color: #000000;">   public function onRollOutHandler<span style="color: #66cc66;">&#40;</span>e:MouseEvent<span style="color: #66cc66;">&#41;</span>:void<span style="color: #66cc66;">&#123;</span></span>
<span style="color: #000000;">    cursorManager.removeCursor<span style="color: #66cc66;">&#40;</span>cursorID<span style="color: #66cc66;">&#41;</span>;</span>
<span style="color: #000000;">    removeEventListener<span style="color: #66cc66;">&#40;</span>MouseEvent.MOUSE_MOVE, onMouseEventHandler<span style="color: #66cc66;">&#41;</span>;</span>
<span style="color: #000000;">    removeEventListener<span style="color: #66cc66;">&#40;</span>MouseEvent.MOUSE_DOWN, onMouseEventHandler<span style="color: #66cc66;">&#41;</span>;</span>
<span style="color: #000000;">    removeEventListener<span style="color: #66cc66;">&#40;</span>MouseEvent.MOUSE_UP, onMouseEventHandler<span style="color: #66cc66;">&#41;</span>;</span>
<span style="color: #000000;">   <span style="color: #66cc66;">&#125;</span></span>
&nbsp;
<span style="color: #000000;">   public function onMouseEventHandler<span style="color: #66cc66;">&#40;</span>e:MouseEvent<span style="color: #66cc66;">&#41;</span>:void<span style="color: #66cc66;">&#123;</span></span>
<span style="color: #000000;">    cursorTxt.text = e.type + <span style="color: #ff0000;">&quot; (&quot;</span>+ e.localX + <span style="color: #ff0000;">&quot; : &quot;</span> + e.localY + <span style="color: #ff0000;">&quot;)&quot;</span>;</span>
<span style="color: #000000;">   <span style="color: #66cc66;">&#125;</span></span>
<span style="color: #000000;">  <span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#93;</span><span style="color: #7400FF;">&gt;</span></span>
 <span style="color: #000000;"><span style="color: #7400FF;">&lt;/fx:Script</span><span style="color: #7400FF;">&gt;</span></span>
<span style="color: #000000;"><span style="color: #7400FF;">&lt;/s:Panel</span><span style="color: #7400FF;">&gt;</span></span></pre></div></div>

<p>CustomCursorPanel2 實際範例</p>
<p>
<object width="500" height="400">
<param name="movie" value="http://blog-uploads.richmediaplus.com/2011/11/CustomCursorPanel2.swf"></param>
<param name="quality" value="high"></param>
<param name="wmode" value="window"></param>
<param name="menu" value="false"></param>
<param name="bgcolor" value="#FFFFFF"></param>
<param name="allowScriptAccess" value="always"></param>
<embed type="application/x-shockwave-flash" width="500" height="400" src="http://blog-uploads.richmediaplus.com/2011/11/CustomCursorPanel2.swf" quality="high" bgcolor="#FFFFFF" wmode="window" menu="false" ></embed>
</object>
</p>
<p><a href="https://sites.google.com/site/riafiles/CustomCursorInstance.fxp?attredirects=0&#038;d=1">原始檔案下載</a></p>
<p>Related posts:<ol>
<li><a href='http://blog.richmediaplus.com/2011/08/mxmlc-define-embed-source/' rel='bookmark' title='Flex Compiler 編譯參數嵌入外部資源技巧'>Flex Compiler 編譯參數嵌入外部資源技巧</a></li>
<li><a href='http://blog.richmediaplus.com/2011/06/flex-spark-preloader-disappear/' rel='bookmark' title='解決 Flex 4.x 下載進度不出現的問題'>解決 Flex 4.x 下載進度不出現的問題</a></li>
<li><a href='http://blog.richmediaplus.com/2011/10/secureswf-sub-appdomain-issue/' rel='bookmark' title='SecureSWF 與外部模組的陷阱'>SecureSWF 與外部模組的陷阱</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://blog.richmediaplus.com/2011/11/custom-flex-cursor-instance/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Flex App 直接引用外部 Module 的問題</title>
		<link>http://blog.richmediaplus.com/2011/11/direct-referenced-module-issue/</link>
		<comments>http://blog.richmediaplus.com/2011/11/direct-referenced-module-issue/#comments</comments>
		<pubDate>Fri, 04 Nov 2011 04:19:37 +0000</pubDate>
		<dc:creator>Ticore Shih</dc:creator>
				<category><![CDATA[ActionScript3]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[Adobe Flex]]></category>
		<category><![CDATA[Module]]></category>

		<guid isPermaLink="false">http://blog.richmediaplus.com/?p=875</guid>
		<description><![CDATA[最近同事遇到一個 Flex 問題，只要 Module 內放了其它組件 執行就會出現各種奇怪 Error 後來發現是因為在 Main Application 直接引用編譯到 Module Class 然後又企圖用 ModuleLoader 再載入一次相同的 Module SWF 當然這樣做是錯誤的範例，Flash Builder 也會給予警告 Warning: Mod is a module or application that is directly referenced. This will cause Mod and all of its dependencies to be linked in with MainApp. Using an interface is the recommended practice to [...]
Related posts:<ol>
<li><a href='http://blog.richmediaplus.com/2011/10/robotlegs-module-issue/' rel='bookmark' title='RobotLegs Module 開發上的問題'>RobotLegs Module 開發上的問題</a></li>
<li><a href='http://blog.richmediaplus.com/2011/05/flex-style-module/' rel='bookmark' title='Flex 4 Style Module'>Flex 4 Style Module</a></li>
<li><a href='http://blog.richmediaplus.com/2011/05/flex-3-style-module/' rel='bookmark' title='Flex 3 Style Module'>Flex 3 Style Module</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>最近同事遇到一個 Flex 問題，只要 Module 內放了其它組件<br />
執行就會出現各種奇怪 Error<br />
後來發現是因為在 Main Application 直接引用編譯到 Module Class<br />
然後又企圖用 ModuleLoader 再載入一次相同的 Module SWF<br />
當然這樣做是錯誤的範例，Flash Builder 也會給予警告</p>
<p>Warning: Mod is a module or application that is directly referenced.<br />
This will cause Mod and all of its dependencies to be linked in with MainApp.<br />
Using an interface is the recommended practice to avoid this.</p>
<p>不要明確引用就正常了<br />
不過還是覺得有點不合理，至少應該能正常執行吧</p>
<p>譬如以下的例子 MainApp.mxml</p>

<div class="wp_syntax"><div class="code"><pre class="mxml" style="font-family:monospace;"><span style="color: #000000;">&lt;?xml version=<span style="color: #ff0000;">&quot;1.0&quot;</span> encoding=<span style="color: #ff0000;">&quot;utf-8&quot;</span>?<span style="color: #7400FF;">&gt;</span></span>
<span style="color: #000000;"><span style="color: #7400FF;">&lt;s:Application</span> xmlns:fx=<span style="color: #ff0000;">&quot;http://ns.adobe.com/mxml/2009&quot;</span> </span>
<span style="color: #000000;">     xmlns:s=<span style="color: #ff0000;">&quot;library://ns.adobe.com/flex/spark&quot;</span> </span>
<span style="color: #000000;">     xmlns:mx=<span style="color: #ff0000;">&quot;library://ns.adobe.com/flex/mx&quot;</span><span style="color: #7400FF;">&gt;</span></span>
 <span style="color: #000000;"><span style="color: #7400FF;">&lt;fx:Script</span><span style="color: #7400FF;">&gt;</span></span>
  <span style="color: #000000;">&lt;!<span style="color: #66cc66;">&#91;</span>CDATA<span style="color: #66cc66;">&#91;</span></span>
<span style="color: #000000;">   Mod;</span>
<span style="color: #000000;">  <span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#93;</span><span style="color: #7400FF;">&gt;</span></span>
 <span style="color: #000000;"><span style="color: #7400FF;">&lt;/fx:Script</span><span style="color: #7400FF;">&gt;</span></span>
 <span style="color: #000000;"><span style="color: #7400FF;">&lt;s:layout</span><span style="color: #7400FF;">&gt;</span></span>
  <span style="color: #000000;"><span style="color: #7400FF;">&lt;s:VerticalLayout</span> verticalAlign=<span style="color: #ff0000;">&quot;middle&quot;</span> horizontalAlign=<span style="color: #ff0000;">&quot;center&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
 <span style="color: #000000;"><span style="color: #7400FF;">&lt;/s:layout</span><span style="color: #7400FF;">&gt;</span></span>
 <span style="color: #000000;"><span style="color: #7400FF;">&lt;s:ModuleLoader</span> id=<span style="color: #ff0000;">&quot;modLdr&quot;</span> url=<span style="color: #ff0000;">&quot;Mod.swf&quot;</span> width=<span style="color: #ff0000;">&quot;50%&quot;</span> height=<span style="color: #ff0000;">&quot;50%&quot;</span><span style="color: #7400FF;">/&gt;</span></span>
<span style="color: #000000;"><span style="color: #7400FF;">&lt;/s:Application</span><span style="color: #7400FF;">&gt;</span></span></pre></div></div>

<p>直接引用到外部 Module，又企圖載入一次同一個外部 Module &#8211; Mod.mxml</p>

<div class="wp_syntax"><div class="code"><pre class="mxml" style="font-family:monospace;"><span style="color: #000000;">&lt;?xml version=<span style="color: #ff0000;">&quot;1.0&quot;</span> encoding=<span style="color: #ff0000;">&quot;utf-8&quot;</span>?<span style="color: #7400FF;">&gt;</span></span>
<span style="color: #000000;"><span style="color: #7400FF;">&lt;s:Module</span> xmlns:fx=<span style="color: #ff0000;">&quot;http://ns.adobe.com/mxml/2009&quot;</span></span>
<span style="color: #000000;">  xmlns:s=<span style="color: #ff0000;">&quot;library://ns.adobe.com/flex/spark&quot;</span></span>
<span style="color: #000000;">  xmlns:mx=<span style="color: #ff0000;">&quot;library://ns.adobe.com/flex/mx&quot;</span></span>
<span style="color: #000000;">  width=<span style="color: #ff0000;">&quot;100%&quot;</span> height=<span style="color: #ff0000;">&quot;100%&quot;</span><span style="color: #7400FF;">&gt;</span></span>
 <span style="color: #000000;"><span style="color: #7400FF;">&lt;s:Panel</span> width=<span style="color: #ff0000;">&quot;100%&quot;</span> height=<span style="color: #ff0000;">&quot;100%&quot;</span> title=<span style="color: #ff0000;">&quot;Module&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
<span style="color: #000000;"><span style="color: #7400FF;">&lt;/s:Module</span><span style="color: #7400FF;">&gt;</span></span></pre></div></div>

<p>隨著 Module 內放置組件不同，可能會得到以下各種錯誤訊息</p>
<p>Main Thread (Suspended: ArgumentError: Error #2004: 有一個參數無效。)<br />
 flash.display::Graphics/drawRect [no source]<br />
 spark.components.supportClasses::TextBase/updateDisplayList<br />
 mx.core::UIComponent/validateDisplayList<br />
 mx.managers::LayoutManager/validateDisplayList<br />
 mx.managers::LayoutManager/doPhasedInstantiation<br />
 mx.managers::LayoutManager/doPhasedInstantiationCallback</p>
<p>Main Thread (Suspended: TypeError: Error #1009: 無法存取 Null 物件參考的屬性或方法。)<br />
 mx.core::UIComponent/getStyle<br />
 mx.core::UIComponent/getConstraintValue<br />
 mx.core::UIComponent/get horizontalCenter<br />
 spark.layouts::BasicLayout/measure<br />
 spark.components.supportClasses::GroupBase/measure<br />
 mx.core::UIComponent/measureSizes<br />
 mx.core::UIComponent/validateSize<br />
 spark.components::Group/validateSize<br />
 mx.managers::LayoutManager/validateSize<br />
 mx.managers::LayoutManager/doPhasedInstantiation<br />
 mx.managers::LayoutManager/doPhasedInstantiationCallback</p>
<p>Flex ModuleLoader 預設載入外部 Module 時<br />
是會從目前 ApplicationDomain 建立一個 child ApplicationDomain 作為載入之用<br />
也就是說假如 Main App 已經包含一份 Module 定義<br />
再載入同名類別，就會被前面的類別定義覆蓋<br />
實際上，被 new 出來的實體其實是 Main App 內定義的</p>
<p>假如兩份定義完全一樣，應該也是要能正常執行吧<br />
問題就是出在這裡了，用 ASV 分別去觀察兩個 SWF 內的 Module 類別<br />
發現是不一樣的！</p>
<p><a href="http://blog-uploads.richmediaplus.com/2011/11/DirectRefModuleIssue.png"><img src="http://blog-uploads.richmediaplus.com/2011/11/DirectRefModuleIssue-300x168.png" alt="" title="DirectRefModuleIssue" width="300" height="168" class="alignnone size-medium wp-image-876" /></a></p>
<p>當 Flex Module 編譯為獨立 SWF 時<br />
MXMLC Compiler 會塞入一些額外的 Metadata Tag, Code&#8230; 做初始化<br />
可是 MainApp 內的 Module 定義少了這些動作，導致無法正常執行</p>
<p>解決的方式不難，ModuleLoader Ready 時<br />
自己手動執行一下關鍵的初始動作就好了 &#8211; styleManager.initProtoChainRoots();</p>

<div class="wp_syntax"><div class="code"><pre class="mxml" style="font-family:monospace;"><span style="color: #000000;"><span style="color: #7400FF;">&lt;s:Application</span> xmlns:fx=<span style="color: #ff0000;">&quot;http://ns.adobe.com/mxml/2009&quot;</span> </span>
<span style="color: #000000;">     xmlns:s=<span style="color: #ff0000;">&quot;library://ns.adobe.com/flex/spark&quot;</span> </span>
<span style="color: #000000;">     xmlns:mx=<span style="color: #ff0000;">&quot;library://ns.adobe.com/flex/mx&quot;</span><span style="color: #7400FF;">&gt;</span></span>
 <span style="color: #000000;"><span style="color: #7400FF;">&lt;fx:Script</span><span style="color: #7400FF;">&gt;</span></span>
  <span style="color: #000000;">&lt;!<span style="color: #66cc66;">&#91;</span>CDATA<span style="color: #66cc66;">&#91;</span></span>
<span style="color: #000000;">   Mod;</span>
<span style="color: #000000;">  <span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#93;</span><span style="color: #7400FF;">&gt;</span></span>
 <span style="color: #000000;"><span style="color: #7400FF;">&lt;/fx:Script</span><span style="color: #7400FF;">&gt;</span></span>
 <span style="color: #000000;"><span style="color: #7400FF;">&lt;s:layout</span><span style="color: #7400FF;">&gt;</span></span>
  <span style="color: #000000;"><span style="color: #7400FF;">&lt;s:VerticalLayout</span> verticalAlign=<span style="color: #ff0000;">&quot;middle&quot;</span> horizontalAlign=<span style="color: #ff0000;">&quot;center&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
 <span style="color: #000000;"><span style="color: #7400FF;">&lt;/s:layout</span><span style="color: #7400FF;">&gt;</span></span>
 <span style="color: #000000;"><span style="color: #7400FF;">&lt;s:ModuleLoader</span> id=<span style="color: #ff0000;">&quot;modLdr&quot;</span> url=<span style="color: #ff0000;">&quot;Mod.swf&quot;</span> width=<span style="color: #ff0000;">&quot;50%&quot;</span> height=<span style="color: #ff0000;">&quot;50%&quot;</span></span>
<span style="color: #000000;">   ready=<span style="color: #ff0000;">&quot;event.target.child.styleManager.initProtoChainRoots();&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
<span style="color: #000000;"><span style="color: #7400FF;">&lt;/s:Application</span><span style="color: #7400FF;">&gt;</span></span></pre></div></div>

<p>Related posts:<ol>
<li><a href='http://blog.richmediaplus.com/2011/10/robotlegs-module-issue/' rel='bookmark' title='RobotLegs Module 開發上的問題'>RobotLegs Module 開發上的問題</a></li>
<li><a href='http://blog.richmediaplus.com/2011/05/flex-style-module/' rel='bookmark' title='Flex 4 Style Module'>Flex 4 Style Module</a></li>
<li><a href='http://blog.richmediaplus.com/2011/05/flex-3-style-module/' rel='bookmark' title='Flex 3 Style Module'>Flex 3 Style Module</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://blog.richmediaplus.com/2011/11/direct-referenced-module-issue/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>AS3 Cross Join Function</title>
		<link>http://blog.richmediaplus.com/2011/11/as3-cross-join-function/</link>
		<comments>http://blog.richmediaplus.com/2011/11/as3-cross-join-function/#comments</comments>
		<pubDate>Tue, 01 Nov 2011 11:23:03 +0000</pubDate>
		<dc:creator>Ticore Shih</dc:creator>
				<category><![CDATA[ActionScript3]]></category>
		<category><![CDATA[Flash]]></category>

		<guid isPermaLink="false">http://blog.richmediaplus.com/?p=871</guid>
		<description><![CDATA[昨天想要用各種不同條件測試 Flash AS3 的畫線 用過 graphics.lineStyle 應該知道參數很多種 但總不可能把各種條件組合通通打出來測試 就算用一般 Loop 方式，也要寫到四~五層 Loop 於是想要寫一個類似 SQL Cross Join 的 function 可以傳入不定數量的資料，將所有排列組合結果找出來 一開始寫時候，大約用了十來行 不斷改進之後，程式碼比想像中少很多 而且連一個區域變數都沒宣告 用了三層 Loop 完成 以下便是 AS3 Cross Join 公用函式： package com.ticore.utils &#123; /** * 排列組合公用函式，可以對傳入的二維參數陣列 * 找出各種組合，並將結果陣列回傳 * * @param args 任意數量的二維參數陣列 * @param res 欲與其它條件再組合的結果陣列 * @return 二維結果陣列 * @author Ticore Shih * [...]
Related posts:<ol>
<li><a href='http://blog.richmediaplus.com/2011/10/flash-player-11-array-bug/' rel='bookmark' title='Flash Player 11 Array Bug'>Flash Player 11 Array Bug</a></li>
<li><a href='http://blog.richmediaplus.com/2011/05/decide-folat-point-precision/' rel='bookmark' title='決定浮點數有效位數'>決定浮點數有效位數</a></li>
<li><a href='http://blog.richmediaplus.com/2011/07/as3-static-function-variable/' rel='bookmark' title='AS3 Static Function Variable'>AS3 Static Function Variable</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>昨天想要用各種不同條件測試 Flash AS3 的畫線<br />
用過 graphics.lineStyle 應該知道參數很多種<br />
但總不可能把各種條件組合通通打出來測試<br />
就算用一般 Loop 方式，也要寫到四~五層 Loop<br />
於是想要寫一個類似 SQL Cross Join 的 function<br />
可以傳入不定數量的資料，將所有排列組合結果找出來</p>
<p>一開始寫時候，大約用了十來行<br />
不斷改進之後，程式碼比想像中少很多<br />
而且連一個區域變數都沒宣告<br />
用了三層 Loop 完成</p>
<p>以下便是 AS3 Cross Join 公用函式：</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #9900cc; font-weight: bold;">package</span> com<span style="color: #000066; font-weight: bold;">.</span>ticore<span style="color: #000066; font-weight: bold;">.</span>utils <span style="color: #000000;">&#123;</span>
 <span style="color: #3f5fbf;">/**
  * 排列組合公用函式，可以對傳入的二維參數陣列
  * 找出各種組合，並將結果陣列回傳
  * 
  * @param args 任意數量的二維參數陣列
  * @param res 欲與其它條件再組合的結果陣列
  * @return 二維結果陣列
  * @author Ticore Shih
  * 
  * @example 以下例子會找出 [A, B] 與 [0, 1, 2] 所有可能的組合
  * &lt;listing version=&quot;3.0&quot;&gt;
  * trace(crossJoin([[&quot;A&quot;, &quot;B&quot;], [0, 1, 2]]).join(&quot;\n&quot;));
  * &lt;/listing&gt;
  */</span>
 <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> crossJoin<span style="color: #000000;">&#40;</span>args<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Array</span><span style="color: #000066; font-weight: bold;">,</span> res<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Array</span> = <span style="color: #0033ff; font-weight: bold;">null</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Array</span><span style="color: #000000;">&#123;</span>
  args<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">forEach</span><span style="color: #000000;">&#40;</span><span style="color: #339966; font-weight: bold;">function</span><span style="color: #000000;">&#40;</span>o0<span style="color: #000066; font-weight: bold;">:*,</span> i0<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">int</span><span style="color: #000066; font-weight: bold;">,</span> a0<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Array</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span><span style="color: #000000;">&#123;</span>
   <span style="color: #000000;">&#40;</span>res <span style="color: #000066; font-weight: bold;">||</span>= <span style="color: #000000;">&#91;</span><span style="color: #000000;">&#91;</span><span style="color: #000000;">&#93;</span><span style="color: #000000;">&#93;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">splice</span><span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">0</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">forEach</span><span style="color: #000000;">&#40;</span><span style="color: #339966; font-weight: bold;">function</span><span style="color: #000000;">&#40;</span>o1<span style="color: #000066; font-weight: bold;">:*,</span> i1<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">int</span><span style="color: #000066; font-weight: bold;">,</span> a1<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Array</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span><span style="color: #000000;">&#123;</span>
    o0<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">forEach</span><span style="color: #000000;">&#40;</span><span style="color: #339966; font-weight: bold;">function</span><span style="color: #000000;">&#40;</span>o2<span style="color: #000066; font-weight: bold;">:*,</span> i2<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">int</span><span style="color: #000066; font-weight: bold;">,</span> a2<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Array</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span><span style="color: #000000;">&#123;</span>
     res<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">push</span><span style="color: #000000;">&#40;</span>o1<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">concat</span><span style="color: #000000;">&#40;</span>o2<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
    <span style="color: #000000;">&#125;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
   <span style="color: #000000;">&#125;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
  <span style="color: #000000;">&#125;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
  <span style="color: #0033ff; font-weight: bold;">return</span> res<span style="color: #000066; font-weight: bold;">;</span>
 <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>實際使用例子</p>
<p>trace(crossJoin([['a', 'b']], crossJoin([["A", "B"], [0, 1, 2]])).join(“\n”));<br />
/*/<br />
A,0,a<br />
A,0,b<br />
A,1,a<br />
A,1,b<br />
A,2,a<br />
A,2,b<br />
B,0,a<br />
B,0,b<br />
B,1,a<br />
B,1,b<br />
B,2,a<br />
B,2,b<br />
//*/</p>
<p>當然也可以一次 Join 完三層條件</p>
<p>trace(crossJoin([["A", "B"], [0, 1, 2], ['a', 'b']]).join(“\n”));</p>
<p>Related posts:<ol>
<li><a href='http://blog.richmediaplus.com/2011/10/flash-player-11-array-bug/' rel='bookmark' title='Flash Player 11 Array Bug'>Flash Player 11 Array Bug</a></li>
<li><a href='http://blog.richmediaplus.com/2011/05/decide-folat-point-precision/' rel='bookmark' title='決定浮點數有效位數'>決定浮點數有效位數</a></li>
<li><a href='http://blog.richmediaplus.com/2011/07/as3-static-function-variable/' rel='bookmark' title='AS3 Static Function Variable'>AS3 Static Function Variable</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://blog.richmediaplus.com/2011/11/as3-cross-join-function/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>RobotLegs Module 開發上的問題</title>
		<link>http://blog.richmediaplus.com/2011/10/robotlegs-module-issue/</link>
		<comments>http://blog.richmediaplus.com/2011/10/robotlegs-module-issue/#comments</comments>
		<pubDate>Sat, 22 Oct 2011 13:02:08 +0000</pubDate>
		<dc:creator>Ticore Shih</dc:creator>
				<category><![CDATA[ActionScript3]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[Adobe Flex]]></category>
		<category><![CDATA[MVC]]></category>
		<category><![CDATA[RebotLegs]]></category>

		<guid isPermaLink="false">http://blog.richmediaplus.com/?p=868</guid>
		<description><![CDATA[最近開始使用 RobotLegs，覺得還蠻好用的，可以少寫很多程式碼 雖然有一些效能上的問題，但可以透過自己管理創建/銷毀時機方式避開 當想要把它用在 Flex Module 開發時，又遇到了一些問題 找不到任何良好的 RobotLegs Modular 開發範例 雖然有人寫了 Modular Utilities，且有提供範例 ModularDoodads 但是坦白說，寫的很糟糕 Module 與主程式綁在一起，無法拆成獨立外部檔案 又有人基於 Modular Utilities 寫了另一個範例 DynModules 終於將 Module 拆成外部檔案了 不過仔細一看，原來它 Hard Code 硬將 Module 載入到 ApplicationDomain.currentDomain 表示 Module 永遠無法卸載，又是另一個骯髒的範例 於是只好自己想辦法解決這問題 我的初步需求很簡單，Module 並不需要與主程式共用 Context or Injector Module 有自己獨立的 Context，只是與主程式共用 RobotLegs Lib. 而已 僅僅只是這樣都遇到了問題 以下便是簡化的測試程式： Main.mxml &#60;?xml version=&#34;1.0&#34; encoding=&#34;utf-8&#34;?&#62; &#60;s:Application [...]
Related posts:<ol>
<li><a href='http://blog.richmediaplus.com/2011/05/flex-3-style-module/' rel='bookmark' title='Flex 3 Style Module'>Flex 3 Style Module</a></li>
<li><a href='http://blog.richmediaplus.com/2011/05/flex-style-module/' rel='bookmark' title='Flex 4 Style Module'>Flex 4 Style Module</a></li>
<li><a href='http://blog.richmediaplus.com/2011/11/direct-referenced-module-issue/' rel='bookmark' title='Flex App 直接引用外部 Module 的問題'>Flex App 直接引用外部 Module 的問題</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>最近開始使用 RobotLegs，覺得還蠻好用的，可以少寫很多程式碼<br />
雖然有一些效能上的問題，但可以透過自己管理創建/銷毀時機方式避開</p>
<p>當想要把它用在 Flex Module 開發時，又遇到了一些問題<br />
找不到任何良好的 RobotLegs Modular 開發範例<br />
雖然有人寫了 <a href="https://github.com/joelhooks/robotlegs-utilities-Modular">Modular Utilities</a>，且有提供<a href="https://github.com/joelhooks/robotlegs-examples-ModularDoodads">範例 ModularDoodads</a><br />
但是坦白說，寫的很糟糕<br />
Module 與主程式綁在一起，無法拆成獨立外部檔案</p>
<p>又有人基於 Modular Utilities 寫了另一個<a href="http://labs.riamore.com/content/robotlegs/examples/dynmodules">範例 DynModules</a><br />
終於將 Module 拆成外部檔案了<br />
不過仔細一看，原來它 Hard Code 硬將 Module 載入到 ApplicationDomain.currentDomain<br />
表示 Module 永遠無法卸載，又是另一個骯髒的範例<br />
於是只好自己想辦法解決這問題</p>
<p>我的初步需求很簡單，Module 並不需要與主程式共用 Context or Injector<br />
Module 有自己獨立的 Context，只是與主程式共用 RobotLegs Lib. 而已<br />
僅僅只是這樣都遇到了問題<br />
以下便是簡化的測試程式：</p>
<p>Main.mxml</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #000066; font-weight: bold;">&lt;?</span>xml <span style="color: #004993;">version</span>=<span style="color: #990000;">&quot;1.0&quot;</span> encoding=<span style="color: #990000;">&quot;utf-8&quot;</span><span style="color: #000066; font-weight: bold;">?&gt;</span>
<span style="color: #000066; font-weight: bold;">&lt;</span>s<span style="color: #000066; font-weight: bold;">:</span>Application xmlns<span style="color: #000066; font-weight: bold;">:</span>fx=<span style="color: #990000;">&quot;http://ns.adobe.com/mxml/2009&quot;</span>
  xmlns<span style="color: #000066; font-weight: bold;">:</span>s=<span style="color: #990000;">&quot;library://ns.adobe.com/flex/spark&quot;</span>
  xmlns<span style="color: #000066; font-weight: bold;">:</span>mx=<span style="color: #990000;">&quot;library://ns.adobe.com/flex/mx&quot;</span><span style="color: #000066; font-weight: bold;">&gt;</span>
 <span style="color: #000066; font-weight: bold;">&lt;</span>fx<span style="color: #000066; font-weight: bold;">:</span>Script<span style="color: #000066; font-weight: bold;">&gt;</span>
  <span style="color: #000066; font-weight: bold;">&lt;!</span><span style="color: #000000;">&#91;</span>CDATA<span style="color: #000000;">&#91;</span>
   <span style="color: #0033ff; font-weight: bold;">import</span> org<span style="color: #000066; font-weight: bold;">.</span>robotlegs<span style="color: #000066; font-weight: bold;">.</span>mvcs<span style="color: #000066; font-weight: bold;">.*;</span>
&nbsp;
   <span style="color: #009900; font-style: italic;">// include RobotLegs framework.</span>
   Actor<span style="color: #000066; font-weight: bold;">;</span>
   Command<span style="color: #000066; font-weight: bold;">;</span>
   Context<span style="color: #000066; font-weight: bold;">;</span>
   Mediator<span style="color: #000066; font-weight: bold;">;</span>
  <span style="color: #000000;">&#93;</span><span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">&gt;</span>
 <span style="color: #000066; font-weight: bold;">&lt;/</span>fx<span style="color: #000066; font-weight: bold;">:</span>Script<span style="color: #000066; font-weight: bold;">&gt;</span>
 <span style="color: #000066; font-weight: bold;">&lt;</span>s<span style="color: #000066; font-weight: bold;">:</span>ModuleLoader <span style="color: #004993;">url</span>=<span style="color: #990000;">&quot;modules/RLModule.swf&quot;</span> <span style="color: #000066; font-weight: bold;">/&gt;</span>
<span style="color: #000066; font-weight: bold;">&lt;/</span>s<span style="color: #000066; font-weight: bold;">:</span>Application<span style="color: #000066; font-weight: bold;">&gt;</span></pre></div></div>

<p>modules/RLModule.mxml</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #000066; font-weight: bold;">&lt;?</span>xml <span style="color: #004993;">version</span>=<span style="color: #990000;">&quot;1.0&quot;</span> encoding=<span style="color: #990000;">&quot;utf-8&quot;</span><span style="color: #000066; font-weight: bold;">?&gt;</span>
<span style="color: #000066; font-weight: bold;">&lt;</span>s<span style="color: #000066; font-weight: bold;">:</span>Module xmlns<span style="color: #000066; font-weight: bold;">:</span>fx=<span style="color: #990000;">&quot;http://ns.adobe.com/mxml/2009&quot;</span>
  xmlns<span style="color: #000066; font-weight: bold;">:</span>s=<span style="color: #990000;">&quot;library://ns.adobe.com/flex/spark&quot;</span>
  xmlns<span style="color: #000066; font-weight: bold;">:</span>mx=<span style="color: #990000;">&quot;library://ns.adobe.com/flex/mx&quot;</span> xmlns<span style="color: #000066; font-weight: bold;">:</span>modules=<span style="color: #990000;">&quot;modules.*&quot;</span><span style="color: #000066; font-weight: bold;">&gt;</span>
 <span style="color: #000066; font-weight: bold;">&lt;</span>fx<span style="color: #000066; font-weight: bold;">:</span>Declarations<span style="color: #000066; font-weight: bold;">&gt;</span>
  <span style="color: #000066; font-weight: bold;">&lt;</span>modules<span style="color: #000066; font-weight: bold;">:</span>RLModuleContext contextView=<span style="color: #990000;">&quot;{this}&quot;</span> <span style="color: #000066; font-weight: bold;">/&gt;</span>
 <span style="color: #000066; font-weight: bold;">&lt;/</span>fx<span style="color: #000066; font-weight: bold;">:</span>Declarations<span style="color: #000066; font-weight: bold;">&gt;</span>
<span style="color: #000066; font-weight: bold;">&lt;/</span>s<span style="color: #000066; font-weight: bold;">:</span>Module<span style="color: #000066; font-weight: bold;">&gt;</span></pre></div></div>

<p>modules/RLModuleContext.as</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #9900cc; font-weight: bold;">package</span> modules <span style="color: #000000;">&#123;</span>
 <span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.system</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">ApplicationDomain</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
 <span style="color: #0033ff; font-weight: bold;">import</span> org<span style="color: #000066; font-weight: bold;">.</span>robotlegs<span style="color: #000066; font-weight: bold;">.</span>mvcs<span style="color: #000066; font-weight: bold;">.</span>Context<span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
 <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #9900cc; font-weight: bold;">class</span> RLModuleContext <span style="color: #0033ff; font-weight: bold;">extends</span> Context <span style="color: #000000;">&#123;</span>
&nbsp;
  override <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> startup<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span><span style="color: #000000;">&#123;</span>
   mediatorMap<span style="color: #000066; font-weight: bold;">.</span>mapView<span style="color: #000000;">&#40;</span>RLModule<span style="color: #000066; font-weight: bold;">,</span> RLModuleMediator<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
  <span style="color: #000000;">&#125;</span>
 <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>modules/RLModuleMediator.as</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #9900cc; font-weight: bold;">package</span> modules <span style="color: #000000;">&#123;</span>
 <span style="color: #0033ff; font-weight: bold;">import</span> org<span style="color: #000066; font-weight: bold;">.</span>robotlegs<span style="color: #000066; font-weight: bold;">.</span>mvcs<span style="color: #000066; font-weight: bold;">.</span>Mediator<span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
 <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #9900cc; font-weight: bold;">class</span> RLModuleMediator <span style="color: #0033ff; font-weight: bold;">extends</span> Mediator <span style="color: #000000;">&#123;</span>
&nbsp;
  <span style="color: #000000;">&#91;</span>Inject<span style="color: #000000;">&#93;</span>
  <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #6699cc; font-weight: bold;">var</span> view<span style="color: #000066; font-weight: bold;">:</span>RLModule<span style="color: #000066; font-weight: bold;">;</span>
 <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>不管有沒有對 RLModule 最佳化，執行就會得到錯誤訊息</p>
<pre>
ReferenceError: Error #1065: 變數 RLModule 未定義。
 at flash.system::ApplicationDomain/getDefinition()
 at org.swiftsuspenders.injectionpoints::PropertyInjectionPoint/applyInjection()
 at org.swiftsuspenders::Injector/injectInto()
 at org.swiftsuspenders::Injector/instantiate()
 at org.robotlegs.base::MediatorMap/createMediatorUsing()
 at org.robotlegs.base::MediatorMap/mapView()
 at modules::RLModuleContext/startup()
 at org.robotlegs.mvcs::Context/onAddedToStage()
 at flash.display::DisplayObjectContainer/addChildAt()
 ...
</pre>
<p>花了一些時間在 RobotLegs 原始碼中找原因<br />
才發現 Context 會替 mediatorMap, commandMap, viewMap 建立 childInjector<br />
而 childInjector 又需要用到 contextView 的 ApplicationDomain<br />
可是一開始 Module 還沒加到舞台上時，loaderInfo 是 null<br />
備份方案變成改取 ApplicationDomain.currentDomain<br />
也就是 Context 類別定義的那一個<br />
當然裡面根本不會有 Module 的類別<br />
結果就是一堆 Error</p>
<p>解決方式就是在 RLModuleContext 自行覆寫一次 getApplicationDomainFromContextView<br />
內容直接從 super 抄一遍就好了</p>
<pre>
  override protected function getApplicationDomainFromContextView():ApplicationDomain{
   if (contextView &#038;&#038; contextView.loaderInfo)
    return contextView.loaderInfo.applicationDomain;
   return ApplicationDomain.currentDomain;
  }
</pre>
<p><a href="https://sites.google.com/site/riafiles/FlexRLModuleIssue.fxp?attredirects=0&#038;d=1">原始檔案下載</a></p>
<p>Related posts:<ol>
<li><a href='http://blog.richmediaplus.com/2011/05/flex-3-style-module/' rel='bookmark' title='Flex 3 Style Module'>Flex 3 Style Module</a></li>
<li><a href='http://blog.richmediaplus.com/2011/05/flex-style-module/' rel='bookmark' title='Flex 4 Style Module'>Flex 4 Style Module</a></li>
<li><a href='http://blog.richmediaplus.com/2011/11/direct-referenced-module-issue/' rel='bookmark' title='Flex App 直接引用外部 Module 的問題'>Flex App 直接引用外部 Module 的問題</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://blog.richmediaplus.com/2011/10/robotlegs-module-issue/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>StarlingFramework</title>
		<link>http://blog.richmediaplus.com/2011/10/starlingframework/</link>
		<comments>http://blog.richmediaplus.com/2011/10/starlingframework/#comments</comments>
		<pubDate>Sat, 22 Oct 2011 10:23:14 +0000</pubDate>
		<dc:creator>milkmidi</dc:creator>
				<category><![CDATA[ActionScript3]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[Starling]]></category>

		<guid isPermaLink="false">http://blog.richmediaplus.com/?p=867</guid>
		<description><![CDATA[Adobe Flash Player11 推出後，最令人開心的是支援 GPU 運算 可以透過顯卡來幫忙，不在只有以往的 CPU。 但要自已從無到有的從底層寫，好像有點辛苦 奶小茶我今天就是要介紹的是一套 2D flash API, 一樣底層是支援 GPU 運算的 StarlingFramework, The GPU powered 2D Flash API http://www.starling-framework.org/ 可以先到官網下載 Source 和 Sample Code. 編譯時，一定要選擇 Flash Player11 才行 這套 FrameWork 的好處，就是寫法長的跟本來的差不多 一樣是叫 Sprite, TextField, Stage, 一樣可以有 addChild 等方法，學起來不會太難 看一下試寫的效果，結合 Box2D, 300個Box, 還可以保持在 30FPS 左右 Related posts: 利用文字欄位偵測舞台縮放比例 將 Box2D Alchemy [...]
Related posts:<ol>
<li><a href='http://blog.richmediaplus.com/2011/07/detect-stage-scale-by-textfield/' rel='bookmark' title='利用文字欄位偵測舞台縮放比例'>利用文字欄位偵測舞台縮放比例</a></li>
<li><a href='http://blog.richmediaplus.com/2011/07/box2d-wck-swc-flash/' rel='bookmark' title='將 Box2D Alchemy WCK 打包為 SWC 類別庫'>將 Box2D Alchemy WCK 打包為 SWC 類別庫</a></li>
<li><a href='http://blog.richmediaplus.com/2011/07/advanced-stage-scale-detector/' rel='bookmark' title='進階版舞台縮放比例偵測器'>進階版舞台縮放比例偵測器</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>Adobe Flash Player11 推出後，最令人開心的是支援 GPU 運算<br />
可以透過顯卡來幫忙，不在只有以往的 CPU。<br />
但要自已從無到有的從底層寫，好像有點辛苦<br />
奶小茶我今天就是要介紹的是一套 2D flash API, 一樣底層是支援 GPU 運算的</p>
<p>StarlingFramework, The GPU powered 2D Flash API<br />
<a href="http://www.starling-framework.org/" target="_blank">http://www.starling-framework.org/</a><br />
可以先到官網下載 Source 和 Sample Code.<br />
編譯時，一定要選擇 Flash Player11 才行<br />
這套 FrameWork 的好處，就是寫法長的跟本來的差不多<br />
一樣是叫 Sprite, TextField, Stage,<br />
一樣可以有 addChild 等方法，學起來不會太難<br />
看一下試寫的效果，結合 Box2D, 300個Box, 還可以保持在 30FPS 左右<br />
<a href="http://dl.dropbox.com/u/2069696/blog/2011_10_11_starling/index.html" target="_blank"><br />
<img src="http://dl.dropbox.com/u/2069696/blog/2011_10_11_starling/blog.png" alt="" /></a></p>
<p>Related posts:<ol>
<li><a href='http://blog.richmediaplus.com/2011/07/detect-stage-scale-by-textfield/' rel='bookmark' title='利用文字欄位偵測舞台縮放比例'>利用文字欄位偵測舞台縮放比例</a></li>
<li><a href='http://blog.richmediaplus.com/2011/07/box2d-wck-swc-flash/' rel='bookmark' title='將 Box2D Alchemy WCK 打包為 SWC 類別庫'>將 Box2D Alchemy WCK 打包為 SWC 類別庫</a></li>
<li><a href='http://blog.richmediaplus.com/2011/07/advanced-stage-scale-detector/' rel='bookmark' title='進階版舞台縮放比例偵測器'>進階版舞台縮放比例偵測器</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://blog.richmediaplus.com/2011/10/starlingframework/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>SecureSWF 與外部模組的陷阱</title>
		<link>http://blog.richmediaplus.com/2011/10/secureswf-sub-appdomain-issue/</link>
		<comments>http://blog.richmediaplus.com/2011/10/secureswf-sub-appdomain-issue/#comments</comments>
		<pubDate>Fri, 21 Oct 2011 05:19:05 +0000</pubDate>
		<dc:creator>Ticore Shih</dc:creator>
				<category><![CDATA[ActionScript3]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[Obfuscate]]></category>
		<category><![CDATA[SecureSWF]]></category>

		<guid isPermaLink="false">http://blog.richmediaplus.com/?p=866</guid>
		<description><![CDATA[使用 SecureSWF 做包含外部模組的專案時，遇到混淆過頭 導致外部 SWF 模組無法正常執行的問題 當然基本的共用類別需要必須先排除在外 可是還是無法正常執行 測試簡化問題之後，發生條件如下 主程式 SWF 包含一共享父類別定義 該類別宣告了 protected getter/setter member 且型別是一個 interface 外部子 SWF 模組繼承此共享父類別 當兩個 SWF 混淆過之後 (排除共享父類別) 外部子 SWF 模組載入後，嘗試存取 super protected member 會得到 ReferenceError: Error #1065: 變數 default::foo 未定義。 以下是測試原始碼： Main.as package &#123; import com.ticore.obfu.SupClass; &#160; import flash.display.Loader; import flash.display.Sprite; import flash.events.Event; import flash.net.URLRequest; import flash.system.ApplicationDomain; [...]
Related posts:<ol>
<li><a href='http://blog.richmediaplus.com/2011/07/advanced-stage-scale-detector/' rel='bookmark' title='進階版舞台縮放比例偵測器'>進階版舞台縮放比例偵測器</a></li>
<li><a href='http://blog.richmediaplus.com/2011/09/fp-102-103-textfield-font-issue/' rel='bookmark' title='Flash Player 10.2, 10.3 TextField 中文字體問題'>Flash Player 10.2, 10.3 TextField 中文字體問題</a></li>
<li><a href='http://blog.richmediaplus.com/2011/07/detect-stage-scale-by-textfield/' rel='bookmark' title='利用文字欄位偵測舞台縮放比例'>利用文字欄位偵測舞台縮放比例</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>使用 <a href="http://www.kindi.com/">SecureSWF</a> 做包含外部模組的專案時，遇到混淆過頭<br />
導致外部 SWF 模組無法正常執行的問題<br />
當然基本的共用類別需要必須先排除在外<br />
可是還是無法正常執行<br />
測試簡化問題之後，發生條件如下</p>
<p>主程式 SWF 包含一共享父類別定義<br />
該類別宣告了 protected getter/setter member<br />
且型別是一個 interface<br />
外部子 SWF 模組繼承此共享父類別</p>
<p>當兩個 SWF 混淆過之後 (排除共享父類別)<br />
外部子 SWF 模組載入後，嘗試存取 super protected member<br />
會得到 ReferenceError: Error #1065: 變數 default::foo 未定義。<br />
以下是測試原始碼：</p>
<p>Main.as</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #9900cc; font-weight: bold;">package</span> <span style="color: #000000;">&#123;</span>
 <span style="color: #0033ff; font-weight: bold;">import</span> com<span style="color: #000066; font-weight: bold;">.</span>ticore<span style="color: #000066; font-weight: bold;">.</span>obfu<span style="color: #000066; font-weight: bold;">.</span>SupClass<span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
 <span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.display</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">Loader</span><span style="color: #000066; font-weight: bold;">;</span>
 <span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.display</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">Sprite</span><span style="color: #000066; font-weight: bold;">;</span>
 <span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.events</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">Event</span><span style="color: #000066; font-weight: bold;">;</span>
 <span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.net</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">URLRequest</span><span style="color: #000066; font-weight: bold;">;</span>
 <span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.system</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">ApplicationDomain</span><span style="color: #000066; font-weight: bold;">;</span>
 <span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.system</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">LoaderContext</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
 <span style="color: #3f5fbf;">/**
  * Main 主程式 SWF
  * 持有共用的 SupClass 類別定義
  * 依據自身 application domain 產生 child domain
  * 用來載入繼承 SupClass 的外部 SWF 模組
  */</span>
 <span style="color: #000000;">&#91;</span>SWF<span style="color: #000000;">&#40;</span><span style="color: #004993;">width</span>=<span style="color: #990000;">&quot;300&quot;</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #004993;">height</span>=<span style="color: #990000;">&quot;200&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span>
 <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #9900cc; font-weight: bold;">class</span> Main <span style="color: #0033ff; font-weight: bold;">extends</span> <span style="color: #004993;">Sprite</span> <span style="color: #000000;">&#123;</span>
&nbsp;
  <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #6699cc; font-weight: bold;">var</span> currAppDom<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">ApplicationDomain</span> = <span style="color: #004993;">ApplicationDomain</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">currentDomain</span><span style="color: #000066; font-weight: bold;">;</span>
  <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #6699cc; font-weight: bold;">var</span> childAppDom<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">ApplicationDomain</span> = <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">ApplicationDomain</span><span style="color: #000000;">&#40;</span>currAppDom<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
  <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #6699cc; font-weight: bold;">var</span> ldr<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Loader</span> = <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">Loader</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
  <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #6699cc; font-weight: bold;">var</span> req<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">URLRequest</span> = <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">URLRequest</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;Mod.swf&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
  <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #6699cc; font-weight: bold;">var</span> ldrCxt<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">LoaderContext</span> = <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">LoaderContext</span><span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">false</span><span style="color: #000066; font-weight: bold;">,</span> childAppDom<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
  <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> Main<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
   <span style="color: #009900; font-style: italic;">// 明確引用父類別定義，編入 parent application domain</span>
   SupClass<span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
   ldr<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">contentLoaderInfo</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">Event</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">COMPLETE</span><span style="color: #000066; font-weight: bold;">,</span> onLoadCompleteHandler<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
   ldr<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">load</span><span style="color: #000000;">&#40;</span>req<span style="color: #000066; font-weight: bold;">,</span> ldrCxt<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
   <span style="color: #004993;">addChild</span><span style="color: #000000;">&#40;</span>ldr<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
  <span style="color: #000000;">&#125;</span>
&nbsp;
  <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> onLoadCompleteHandler<span style="color: #000000;">&#40;</span>e<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Event</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span><span style="color: #000000;">&#123;</span>
   <span style="color: #004993;">trace</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;onLoadCompleteHandler();&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
  <span style="color: #000000;">&#125;</span>
 <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>com/ticore/obfu/SupClass.as</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #9900cc; font-weight: bold;">package</span> com<span style="color: #000066; font-weight: bold;">.</span>ticore<span style="color: #000066; font-weight: bold;">.</span>obfu <span style="color: #000000;">&#123;</span>
 <span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.display</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">Bitmap</span><span style="color: #000066; font-weight: bold;">;</span>
 <span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.display</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">IBitmapDrawable</span><span style="color: #000066; font-weight: bold;">;</span>
 <span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.display</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">Sprite</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
 <span style="color: #3f5fbf;">/**
  * 共用的 SupClass 類別定義
  * 帶有 protected getter/setter 且型別為 interface
  */</span>
 <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #9900cc; font-weight: bold;">class</span> SupClass <span style="color: #0033ff; font-weight: bold;">extends</span> <span style="color: #004993;">Sprite</span> <span style="color: #000000;">&#123;</span>
&nbsp;
  <span style="color: #0033ff; font-weight: bold;">protected</span> <span style="color: #6699cc; font-weight: bold;">var</span> _foo_<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">IBitmapDrawable</span> = <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">Bitmap</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
  <span style="color: #0033ff; font-weight: bold;">protected</span> <span style="color: #339966; font-weight: bold;">function</span> <span style="color: #0033ff; font-weight: bold;">get</span> foo<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">IBitmapDrawable</span> <span style="color: #000000;">&#123;</span>
   <span style="color: #0033ff; font-weight: bold;">return</span> _foo_<span style="color: #000066; font-weight: bold;">;</span>
  <span style="color: #000000;">&#125;</span>
&nbsp;
  <span style="color: #0033ff; font-weight: bold;">protected</span> <span style="color: #339966; font-weight: bold;">function</span> <span style="color: #0033ff; font-weight: bold;">set</span> foo<span style="color: #000000;">&#40;</span><span style="color: #004993;">value</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">IBitmapDrawable</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span><span style="color: #000000;">&#123;</span>
   _foo_ = <span style="color: #004993;">value</span><span style="color: #000066; font-weight: bold;">;</span>
  <span style="color: #000000;">&#125;</span>
 <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>Mod.as</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #9900cc; font-weight: bold;">package</span>  <span style="color: #000000;">&#123;</span>
 <span style="color: #0033ff; font-weight: bold;">import</span> com<span style="color: #000066; font-weight: bold;">.</span>ticore<span style="color: #000066; font-weight: bold;">.</span>obfu<span style="color: #000066; font-weight: bold;">.</span>SupClass<span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
 <span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.display</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">Sprite</span><span style="color: #000066; font-weight: bold;">;</span>
 <span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.text</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">TextField</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
 <span style="color: #3f5fbf;">/**
  * 外部 SWF 模組
  * 繼承共用的 SupClass 類別定義
  * 嘗試用不同方式存取 SupClass protected getter member
  */</span>
 <span style="color: #000000;">&#91;</span>SWF<span style="color: #000000;">&#40;</span><span style="color: #004993;">width</span>=<span style="color: #990000;">&quot;300&quot;</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #004993;">height</span>=<span style="color: #990000;">&quot;200&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span>
 <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #9900cc; font-weight: bold;">class</span> Mod <span style="color: #0033ff; font-weight: bold;">extends</span> SupClass <span style="color: #000000;">&#123;</span>
&nbsp;
  <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #6699cc; font-weight: bold;">var</span> txt<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">TextField</span> = <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">TextField</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
  <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> Mod<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
   <span style="color: #004993;">init</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
   doTrace<span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">Date</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
   <span style="color: #009900; font-style: italic;">// 直接呼叫 super protected getter member 會得到 error</span>
   <span style="color: #0033ff; font-weight: bold;">try</span> <span style="color: #000000;">&#123;</span>
    doTrace<span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;foo:&quot;</span><span style="color: #000066; font-weight: bold;">,</span> foo<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
   <span style="color: #000000;">&#125;</span> <span style="color: #0033ff; font-weight: bold;">catch</span> <span style="color: #000000;">&#40;</span>e<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Error</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
    doTrace<span style="color: #000000;">&#40;</span>e<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
   <span style="color: #000000;">&#125;</span>
&nbsp;
   <span style="color: #009900; font-style: italic;">// 用 with block</span>
   <span style="color: #0033ff; font-weight: bold;">with</span> <span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">0</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
    doTrace<span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;foo:&quot;</span><span style="color: #000066; font-weight: bold;">,</span> foo<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
   <span style="color: #000000;">&#125;</span>
&nbsp;
   <span style="color: #009900; font-style: italic;">// 用關聯陣列存取算子</span>
   doTrace<span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;foo:&quot;</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #0033ff; font-weight: bold;">this</span><span style="color: #000000;">&#91;</span><span style="color: #990000;">&quot;foo&quot;</span><span style="color: #000000;">&#93;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
  <span style="color: #000000;">&#125;</span>
&nbsp;
&nbsp;
  <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> <span style="color: #004993;">init</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span><span style="color: #000000;">&#123;</span>
   txt<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">wordWrap</span> = <span style="color: #0033ff; font-weight: bold;">true</span><span style="color: #000066; font-weight: bold;">;</span>
   txt<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">width</span> = <span style="color: #000000; font-weight:bold;">250</span><span style="color: #000066; font-weight: bold;">;</span>
   txt<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">height</span> = <span style="color: #000000; font-weight:bold;">150</span><span style="color: #000066; font-weight: bold;">;</span>
   txt<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">x</span> = txt<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">y</span> = <span style="color: #000000; font-weight:bold;">25</span><span style="color: #000066; font-weight: bold;">;</span>
   txt<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">border</span> = <span style="color: #0033ff; font-weight: bold;">true</span><span style="color: #000066; font-weight: bold;">;</span>
   <span style="color: #004993;">addChild</span><span style="color: #000000;">&#40;</span>txt<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
  <span style="color: #000000;">&#125;</span>
&nbsp;
  <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> doTrace<span style="color: #000000;">&#40;</span><span style="color: #000066; font-weight: bold;">...</span>args<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span><span style="color: #000000;">&#123;</span>
   <span style="color: #004993;">trace</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">apply</span><span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">null</span><span style="color: #000066; font-weight: bold;">,</span> args<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
   txt<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">appendText</span><span style="color: #000000;">&#40;</span>args<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">join</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot; &quot;</span><span style="color: #000000;">&#41;</span> <span style="color: #000066; font-weight: bold;">+</span> <span style="color: #990000;">&quot;<span style="">\n</span>&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
  <span style="color: #000000;">&#125;</span>
 <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>用來混淆的 Ant Task</p>
<pre>
&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;project name="SecureSWF Test" default="protect main" basedir="."&gt;

 &lt;property environment="env" /&gt;

 &lt;!-- secureSWF Pro v3.61.5987 --&gt;
 &lt;taskdef name="protect"
   classpath="${env.SECURE_SWF_HOME}\secureSWF.jar"
   classname="secureSWF.ant.ProtectTask" /&gt;

 &lt;target name="protect main"&gt;
  &lt;protect outputPath="secure"&gt;
   &lt;fileset dir="bin-release" includes="**.swf"/&gt;
   &lt;rule filter="com.ticore.obfu.*" rename="false" /&gt;
  &lt;/protect&gt;
 &lt;/target&gt;

&lt;/project&gt;
</pre>
<p>非常神奇的是，用 ASV 觀察混淆過的 SWF<br />
明明沒有任何混淆的跡象，可是卻會造成執行失敗<br />
而用 with block 與關聯陣列運算子，卻又能避開問題</p>
<p>解決方式除了上面兩種方式<br />
SecureSWF 還有定義一個參數是 renameProtectedNamespaces<br />
設為 false or off 就可以了</p>
<p><a href="https://sites.google.com/site/riafiles/SecureSWFIssue.zip?attredirects=0&#038;d=1">測試用的 Flash Builder Project 原始檔案下載</a></p>
<p>Related posts:<ol>
<li><a href='http://blog.richmediaplus.com/2011/07/advanced-stage-scale-detector/' rel='bookmark' title='進階版舞台縮放比例偵測器'>進階版舞台縮放比例偵測器</a></li>
<li><a href='http://blog.richmediaplus.com/2011/09/fp-102-103-textfield-font-issue/' rel='bookmark' title='Flash Player 10.2, 10.3 TextField 中文字體問題'>Flash Player 10.2, 10.3 TextField 中文字體問題</a></li>
<li><a href='http://blog.richmediaplus.com/2011/07/detect-stage-scale-by-textfield/' rel='bookmark' title='利用文字欄位偵測舞台縮放比例'>利用文字欄位偵測舞台縮放比例</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://blog.richmediaplus.com/2011/10/secureswf-sub-appdomain-issue/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Flash Player 11 Array Bug</title>
		<link>http://blog.richmediaplus.com/2011/10/flash-player-11-array-bug/</link>
		<comments>http://blog.richmediaplus.com/2011/10/flash-player-11-array-bug/#comments</comments>
		<pubDate>Wed, 12 Oct 2011 12:22:39 +0000</pubDate>
		<dc:creator>Ticore Shih</dc:creator>
				<category><![CDATA[ActionScript3]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[Bug]]></category>
		<category><![CDATA[Flash Player]]></category>

		<guid isPermaLink="false">http://blog.richmediaplus.com/?p=857</guid>
		<description><![CDATA[最近 Flash Player 11 正式版發表不久 網友 Vincent 留言發現空 Array 的 splice 操作會出現問題 測試程式如下 package &#123; import flash.display.Sprite; import flash.system.Capabilities; import flash.text.TextField; &#160; &#91;SWF&#40;width=&#34;300&#34;, height=&#34;200&#34;&#41;&#93; public class FL11ArrayIssue extends Sprite &#123; &#160; public function FL11ArrayIssue&#40;&#41; &#123; trace&#40;Capabilities.version, Capabilities.playerType&#41;; &#160; var ary:Array = new Array&#40;5&#41;; &#160; /*/ 各種修正 FL 11 Array 的方式 ary.push&#40;undefined&#41;; ary.pop&#40;&#41;; &#160; ary.length++; ary.length--; [...]
Related posts:<ol>
<li><a href='http://blog.richmediaplus.com/2011/09/nested-mask-crash-issue/' rel='bookmark' title='巢狀遮罩造成 Flash Player 死機的 Bug'>巢狀遮罩造成 Flash Player 死機的 Bug</a></li>
<li><a href='http://blog.richmediaplus.com/2011/11/as3-cross-join-function/' rel='bookmark' title='AS3 Cross Join Function'>AS3 Cross Join Function</a></li>
<li><a href='http://blog.richmediaplus.com/2011/09/fp-102-103-textfield-font-issue/' rel='bookmark' title='Flash Player 10.2, 10.3 TextField 中文字體問題'>Flash Player 10.2, 10.3 TextField 中文字體問題</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>最近 Flash Player 11 正式版發表不久<br />
網友 Vincent 留言發現空 Array 的 splice 操作會出現問題<br />
測試程式如下</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #9900cc; font-weight: bold;">package</span> <span style="color: #000000;">&#123;</span>
 <span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.display</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">Sprite</span><span style="color: #000066; font-weight: bold;">;</span>
 <span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.system</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">Capabilities</span><span style="color: #000066; font-weight: bold;">;</span>
 <span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.text</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">TextField</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
 <span style="color: #000000;">&#91;</span>SWF<span style="color: #000000;">&#40;</span><span style="color: #004993;">width</span>=<span style="color: #990000;">&quot;300&quot;</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #004993;">height</span>=<span style="color: #990000;">&quot;200&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span>
 <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #9900cc; font-weight: bold;">class</span> FL11ArrayIssue <span style="color: #0033ff; font-weight: bold;">extends</span> <span style="color: #004993;">Sprite</span> <span style="color: #000000;">&#123;</span>
&nbsp;
  <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> FL11ArrayIssue<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
   <span style="color: #004993;">trace</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">Capabilities</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">version</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #004993;">Capabilities</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">playerType</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
   <span style="color: #6699cc; font-weight: bold;">var</span> ary<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Array</span> = <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">Array</span><span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">5</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
   <span style="color: #009966; font-style: italic;">/*/</span> 各種修正 FL <span style="color: #000000; font-weight:bold;">11</span> <span style="color: #004993;">Array</span> 的方式
   ary<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">push</span><span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">undefined</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
   ary<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">pop</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
   ary<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">length</span><span style="color: #000066; font-weight: bold;">++;</span>
   ary<span style="color: #000066; font-weight: bold;">.</span>length<span style="color: #000066; font-weight: bold;">--;</span>
&nbsp;
   ary<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">shift</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
   ary<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">unshift</span><span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">undefined</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
   ary<span style="color: #000000;">&#91;</span><span style="color: #000000; font-weight:bold;">0</span><span style="color: #000000;">&#93;</span> = <span style="color: #0033ff; font-weight: bold;">undefined</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
   ary<span style="color: #000000;">&#91;</span><span style="color: #000000; font-weight:bold;">0</span><span style="color: #000000;">&#93;</span> = <span style="color: #0033ff; font-weight: bold;">null</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
   ary<span style="color: #000000;">&#91;</span><span style="color: #000000; font-weight:bold;">0</span><span style="color: #000000;">&#93;</span> = ary<span style="color: #000000;">&#91;</span><span style="color: #000000; font-weight:bold;">0</span><span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">;</span>
   <span style="color: #009900; font-style: italic;">//*/</span>
&nbsp;
   <span style="color: #004993;">trace</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;[&quot;</span> <span style="color: #000066; font-weight: bold;">+</span> ary<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">join</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot; , &quot;</span><span style="color: #000000;">&#41;</span> <span style="color: #000066; font-weight: bold;">+</span> <span style="color: #990000;">&quot;]&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
   ary<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">splice</span><span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">2</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #000000; font-weight:bold;">1</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #990000;">&quot;X&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
   <span style="color: #004993;">trace</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;[&quot;</span> <span style="color: #000066; font-weight: bold;">+</span> ary<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">join</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot; , &quot;</span><span style="color: #000000;">&#41;</span> <span style="color: #000066; font-weight: bold;">+</span> <span style="color: #990000;">&quot;]&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
   ary<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">splice</span><span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">2</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #000000; font-weight:bold;">1</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #990000;">&quot;Y&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
   <span style="color: #004993;">trace</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;[&quot;</span> <span style="color: #000066; font-weight: bold;">+</span> ary<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">join</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot; , &quot;</span><span style="color: #000000;">&#41;</span> <span style="color: #000066; font-weight: bold;">+</span> <span style="color: #990000;">&quot;]&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
   ary<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">splice</span><span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">2</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #000000; font-weight:bold;">1</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #990000;">&quot;Z&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
   <span style="color: #004993;">trace</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;[&quot;</span> <span style="color: #000066; font-weight: bold;">+</span> ary<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">join</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot; , &quot;</span><span style="color: #000000;">&#41;</span> <span style="color: #000066; font-weight: bold;">+</span> <span style="color: #990000;">&quot;]&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
  <span style="color: #000000;">&#125;</span>
 <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>輸出結果</p>
<p><code><br />
WIN 11,0,1,152 StandAlone<br />
[ ,  ,  ,  , ]<br />
[ ,  , X ,  , ]<br />
[ , Y ,  ,  , ]<br />
[ , Y , Z ,  , ]<br />
</code></p>
<p>解決方式都寫在註解裡面了，最簡單的方式就是明確指定元素 1 位置的數值<br />
需要注意是，一旦 Array.length 縮減成 0，又重新拉長<br />
就需要再次修正一下 Array</p>
<p>Related posts:<ol>
<li><a href='http://blog.richmediaplus.com/2011/09/nested-mask-crash-issue/' rel='bookmark' title='巢狀遮罩造成 Flash Player 死機的 Bug'>巢狀遮罩造成 Flash Player 死機的 Bug</a></li>
<li><a href='http://blog.richmediaplus.com/2011/11/as3-cross-join-function/' rel='bookmark' title='AS3 Cross Join Function'>AS3 Cross Join Function</a></li>
<li><a href='http://blog.richmediaplus.com/2011/09/fp-102-103-textfield-font-issue/' rel='bookmark' title='Flash Player 10.2, 10.3 TextField 中文字體問題'>Flash Player 10.2, 10.3 TextField 中文字體問題</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://blog.richmediaplus.com/2011/10/flash-player-11-array-bug/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Flash Player 10.2, 10.3 TextField 中文字體問題</title>
		<link>http://blog.richmediaplus.com/2011/09/fp-102-103-textfield-font-issue/</link>
		<comments>http://blog.richmediaplus.com/2011/09/fp-102-103-textfield-font-issue/#comments</comments>
		<pubDate>Sat, 24 Sep 2011 10:37:05 +0000</pubDate>
		<dc:creator>Ticore Shih</dc:creator>
				<category><![CDATA[ActionScript3]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[Flash Player]]></category>
		<category><![CDATA[textfield]]></category>

		<guid isPermaLink="false">http://blog.richmediaplus.com/?p=828</guid>
		<description><![CDATA[我是 Ticore，論壇上看有人問 Flash CS5.5 用 AS3 建立的 TextField 無法動態設置中文字體 實際測試之後，發現並不是 Flash IDE 的問題 而是 Flash Player 10.2, 10.3 且當 swf version 為 11, 12 時，TextField 用中文名稱設定字型失效 測試程式碼如下： package &#123; import flash.display.Sprite; import flash.text.TextField; import flash.text.TextFormat; &#160; &#91;SWF&#40;width=&#34;300&#34;, height=&#34;200&#34;&#41;&#93; public class Main extends Sprite &#123; &#160; public function Main&#40;&#41; &#123; var txt:TextField = new TextField&#40;&#41;; // [...]
Related posts:<ol>
<li><a href='http://blog.richmediaplus.com/2011/10/flash-player-11-array-bug/' rel='bookmark' title='Flash Player 11 Array Bug'>Flash Player 11 Array Bug</a></li>
<li><a href='http://blog.richmediaplus.com/2011/09/nested-mask-crash-issue/' rel='bookmark' title='巢狀遮罩造成 Flash Player 死機的 Bug'>巢狀遮罩造成 Flash Player 死機的 Bug</a></li>
<li><a href='http://blog.richmediaplus.com/2011/07/detect-stage-scale-by-textfield/' rel='bookmark' title='利用文字欄位偵測舞台縮放比例'>利用文字欄位偵測舞台縮放比例</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>我是 Ticore，論壇上看有人問 Flash CS5.5 用 AS3 建立的 TextField 無法動態設置中文字體<br />
實際測試之後，發現並不是 Flash IDE 的問題<br />
而是 Flash Player 10.2, 10.3 且當 swf version 為 11, 12 時，TextField 用中文名稱設定字型失效<br />
測試程式碼如下：</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #9900cc; font-weight: bold;">package</span> <span style="color: #000000;">&#123;</span>
	<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.display</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">Sprite</span><span style="color: #000066; font-weight: bold;">;</span>
	<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.text</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">TextField</span><span style="color: #000066; font-weight: bold;">;</span>
	<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.text</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">TextFormat</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
	<span style="color: #000000;">&#91;</span>SWF<span style="color: #000000;">&#40;</span><span style="color: #004993;">width</span>=<span style="color: #990000;">&quot;300&quot;</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #004993;">height</span>=<span style="color: #990000;">&quot;200&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span>
	<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #9900cc; font-weight: bold;">class</span> Main <span style="color: #0033ff; font-weight: bold;">extends</span> <span style="color: #004993;">Sprite</span> <span style="color: #000000;">&#123;</span>
&nbsp;
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> Main<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
			<span style="color: #6699cc; font-weight: bold;">var</span> txt<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">TextField</span> = <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">TextField</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
			<span style="color: #009900; font-style: italic;">// txt.defaultTextFormat = new TextFormat(&quot;Microsoft JhengHei&quot;, 16);</span>
			txt<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">defaultTextFormat</span> = <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">TextFormat</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;微軟正黑體&quot;</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #000000; font-weight:bold;">16</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
			txt<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">text</span> = <span style="color: #990000;">&quot;微軟正黑體&quot;</span><span style="color: #000066; font-weight: bold;">;</span>
			txt<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">x</span> = <span style="color: #000000; font-weight:bold;">100</span><span style="color: #000066; font-weight: bold;">;</span>
			txt<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">y</span> = <span style="color: #000000; font-weight:bold;">50</span><span style="color: #000066; font-weight: bold;">;</span>
			<span style="color: #004993;">addChild</span><span style="color: #000000;">&#40;</span>txt<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
		<span style="color: #000000;">&#125;</span>
	<span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>假如用 Flash CS5.5 發布為 Flash Player 10.2 版本<br />
就會發現 “微軟正黑體” 設置失效<br />
假如改成發布為 Flash Player 10, 10.1 版本<br />
中文字體設置又正常了</p>
<p>最簡單的解決方式是統一使用中文字型的英文名稱<br />
譬如 “微軟正黑體” 英文叫做 “Microsoft JhengHei”<br />
這樣就能成功動態設置中文字型了</p>
<p>可是在 Flash Builder 開發上，SDK 都有最低 Player 版本的限制<br />
無法隨意亂設 Player Version<br />
另一方面，這個設定值也是需要對應 SDK 目錄下有 playerglobal.swc<br />
假如真的確定程式碼內沒有需要用到 Player 10.2, 10.3 新 API 話<br />
還可以用編譯參數 -swf-version=10 的方式，來改善這問題</p>
<p>SWF 版本與 Player 版本對照可以參考這裡<br />
<a href="http://blogs.adobe.com/airodynamics/2011/08/16/versioning-in-flash-runtime-swf-version/">Versioning in Flash Runtime (-swf-version)</a><br />
只要將 SWF 版本設為 10，就算使用 10.3 Player 播放<br />
它也會自動關閉新的 API，以舊版的功能執行<br />
間接避開 TextField 找不到中文字體問題</p>
<p>Related posts:<ol>
<li><a href='http://blog.richmediaplus.com/2011/10/flash-player-11-array-bug/' rel='bookmark' title='Flash Player 11 Array Bug'>Flash Player 11 Array Bug</a></li>
<li><a href='http://blog.richmediaplus.com/2011/09/nested-mask-crash-issue/' rel='bookmark' title='巢狀遮罩造成 Flash Player 死機的 Bug'>巢狀遮罩造成 Flash Player 死機的 Bug</a></li>
<li><a href='http://blog.richmediaplus.com/2011/07/detect-stage-scale-by-textfield/' rel='bookmark' title='利用文字欄位偵測舞台縮放比例'>利用文字欄位偵測舞台縮放比例</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://blog.richmediaplus.com/2011/09/fp-102-103-textfield-font-issue/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Flash 抽色效果濾鏡</title>
		<link>http://blog.richmediaplus.com/2011/09/partial-color-shader/</link>
		<comments>http://blog.richmediaplus.com/2011/09/partial-color-shader/#comments</comments>
		<pubDate>Tue, 20 Sep 2011 06:31:45 +0000</pubDate>
		<dc:creator>Ticore Shih</dc:creator>
				<category><![CDATA[ActionScript3]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[Pixel Bender]]></category>

		<guid isPermaLink="false">http://blog.richmediaplus.com/?p=822</guid>
		<description><![CDATA[我是 Ticore，這次要分享的是用 Pixel Bender 做出來的抽色濾鏡效果 可以依據指定的色彩，調整點陣圖的色彩飽和度 色彩相差越遠的飽和度越低 效果看起來就會像是把特定色彩抽出來了一樣 直接從 RGB 數值去思考會覺得非常難做 其實只要把 RGB 轉為 HSV 色彩模式便簡單許多 拿到 Hue 值之後，便能拿來與設定主色色彩做比較 差越遠的，就把飽和度調得越低 以下便是我自製的 Partial Color Shader 原始碼： &#60;languageVersion : 1.0;&#62; kernel PartialColor &#60; namespace : &#34;PartialColor&#34;; vendor : &#34;Ticore Shih&#34;; version : 1; description : &#34;only keep saturation of assigned color&#34;; &#62; &#123; &#160; parameter float hue [...]
Related posts:<ol>
<li><a href='http://blog.richmediaplus.com/2009/07/virtual-unique-urls-for-flex-flash/' rel='bookmark' title='Virtual Unique URLs for Flex/Flash'>Virtual Unique URLs for Flex/Flash</a></li>
<li><a href='http://blog.richmediaplus.com/2011/06/avoid-flash-blend-mode-issue/' rel='bookmark' title='Flash 混色模式的問題與解決方式'>Flash 混色模式的問題與解決方式</a></li>
<li><a href='http://blog.richmediaplus.com/2011/07/timeline-placed-video-smoothing/' rel='bookmark' title='Flash 影格預置 Video 抗鋸齒功能'>Flash 影格預置 Video 抗鋸齒功能</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>我是 Ticore，這次要分享的是用 Pixel Bender 做出來的抽色濾鏡效果<br />
可以依據指定的色彩，調整點陣圖的色彩飽和度<br />
色彩相差越遠的飽和度越低<br />
效果看起來就會像是把特定色彩抽出來了一樣</p>
<p>直接從 RGB 數值去思考會覺得非常難做<br />
其實只要把 RGB 轉為 HSV 色彩模式便簡單許多<br />
拿到 Hue 值之後，便能拿來與設定主色色彩做比較<br />
差越遠的，就把飽和度調得越低<br />
以下便是我自製的 Partial Color Shader 原始碼：</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>languageVersion <span style="color: #339933;">:</span> <span style="color:#800080;">1.0</span><span style="color: #339933;">;&gt;</span>
kernel PartialColor
<span style="color: #339933;">&lt;</span>
    namespace <span style="color: #339933;">:</span> <span style="color: #ff0000;">&quot;PartialColor&quot;</span><span style="color: #339933;">;</span>
    vendor <span style="color: #339933;">:</span> <span style="color: #ff0000;">&quot;Ticore Shih&quot;</span><span style="color: #339933;">;</span>
    version <span style="color: #339933;">:</span> <span style="color: #0000dd;">1</span><span style="color: #339933;">;</span>
    description <span style="color: #339933;">:</span> <span style="color: #ff0000;">&quot;only keep saturation of assigned color&quot;</span><span style="color: #339933;">;</span>
<span style="color: #339933;">&gt;</span>
<span style="color: #009900;">&#123;</span>
&nbsp;
    parameter <span style="color: #993333;">float</span> hue
    <span style="color: #339933;">&lt;</span>
        defaultValue<span style="color: #339933;">:</span> <span style="color:#800080;">0.0</span><span style="color: #339933;">;</span>
        minValue<span style="color: #339933;">:</span> <span style="color:#800080;">0.0</span><span style="color: #339933;">;</span>
        maxValue<span style="color: #339933;">:</span> <span style="color:#800080;">360.0</span><span style="color: #339933;">;</span>
    <span style="color: #339933;">&gt;;</span>
&nbsp;
    parameter <span style="color: #993333;">float</span> range
    <span style="color: #339933;">&lt;</span>
        defaultValue <span style="color: #339933;">:</span> <span style="color:#800080;">40.0</span><span style="color: #339933;">;</span>
        minValue <span style="color: #339933;">:</span> <span style="color:#800080;">0.0</span><span style="color: #339933;">;</span>
        maxValue <span style="color: #339933;">:</span> <span style="color:#800080;">180.0</span><span style="color: #339933;">;</span>
    <span style="color: #339933;">&gt;;</span>
    input image4 src<span style="color: #339933;">;</span>
    output pixel4 dst<span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #993333;">void</span> evaluatePixel<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        pixel4 inputColor <span style="color: #339933;">=</span> sampleNearest<span style="color: #009900;">&#40;</span>src<span style="color: #339933;">,</span> outCoord<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #993333;">float</span> minColor<span style="color: #339933;">,</span> maxColor<span style="color: #339933;">,</span> delta<span style="color: #339933;">;</span>
        <span style="color: #993333;">float</span> h<span style="color: #339933;">,</span> s<span style="color: #339933;">,</span> v<span style="color: #339933;">;</span>
        <span style="color: #993333;">float</span> r<span style="color: #339933;">,</span> g<span style="color: #339933;">,</span> b<span style="color: #339933;">;</span>
        <span style="color: #993333;">float</span> f<span style="color: #339933;">,</span> p<span style="color: #339933;">,</span> q<span style="color: #339933;">,</span> t<span style="color: #339933;">;</span>
        <span style="color: #993333;">int</span> i<span style="color: #339933;">;</span>
&nbsp;
        r <span style="color: #339933;">=</span> inputColor.<span style="color: #202020;">r</span><span style="color: #339933;">;</span> g <span style="color: #339933;">=</span> inputColor.<span style="color: #202020;">g</span><span style="color: #339933;">;</span> b <span style="color: #339933;">=</span> inputColor.<span style="color: #202020;">b</span><span style="color: #339933;">;</span>
&nbsp;
        minColor <span style="color: #339933;">=</span> min<span style="color: #009900;">&#40;</span>min<span style="color: #009900;">&#40;</span>r <span style="color: #339933;">,</span> g<span style="color: #009900;">&#41;</span> <span style="color: #339933;">,</span> b<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        maxColor <span style="color: #339933;">=</span> max<span style="color: #009900;">&#40;</span>max<span style="color: #009900;">&#40;</span>r <span style="color: #339933;">,</span> g<span style="color: #009900;">&#41;</span> <span style="color: #339933;">,</span> b<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        delta <span style="color: #339933;">=</span> maxColor <span style="color: #339933;">-</span> minColor<span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #666666; font-style: italic;">// value</span>
        v <span style="color: #339933;">=</span> maxColor<span style="color: #339933;">;</span>
        <span style="color: #666666; font-style: italic;">// saturation</span>
        <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>maxColor <span style="color: #339933;">!=</span><span style="color:#800080;">0.0</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            s <span style="color: #339933;">=</span> delta <span style="color: #339933;">/</span> maxColor<span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #666666; font-style: italic;">// hue</span>
        <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>maxColor <span style="color: #339933;">==</span> r<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            h <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>g <span style="color: #339933;">-</span> b<span style="color: #009900;">&#41;</span> <span style="color: #339933;">/</span> delta<span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>maxColor <span style="color: #339933;">==</span> g<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            h <span style="color: #339933;">=</span> <span style="color:#800080;">2.0</span> <span style="color: #339933;">+</span> <span style="color: #009900;">&#40;</span>b <span style="color: #339933;">-</span> r<span style="color: #009900;">&#41;</span> <span style="color: #339933;">/</span> delta<span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
            h <span style="color: #339933;">=</span> <span style="color:#800080;">4.0</span> <span style="color: #339933;">+</span> <span style="color: #009900;">&#40;</span>r <span style="color: #339933;">-</span> g<span style="color: #009900;">&#41;</span> <span style="color: #339933;">/</span> delta<span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
        h <span style="color: #339933;">*=</span> <span style="color:#800080;">60.0</span><span style="color: #339933;">;</span>
        h <span style="color: #339933;">=</span> mod<span style="color: #009900;">&#40;</span>h <span style="color: #339933;">+</span> <span style="color:#800080;">360.0</span><span style="color: #339933;">,</span> <span style="color:#800080;">360.0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
        <span style="color: #993333;">float</span> diff <span style="color: #339933;">=</span> min<span style="color: #009900;">&#40;</span>mod<span style="color: #009900;">&#40;</span>abs<span style="color: #009900;">&#40;</span>hue <span style="color: #339933;">-</span> h <span style="color: #339933;">-</span> <span style="color:#800080;">360.0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color:#800080;">360.0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> mod<span style="color: #009900;">&#40;</span>abs<span style="color: #009900;">&#40;</span>hue <span style="color: #339933;">-</span> h <span style="color: #339933;">+</span> <span style="color:#800080;">360.0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color:#800080;">360.0</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #666666; font-style: italic;">// sine</span>
&nbsp;
        s <span style="color: #339933;">*=</span> sin<span style="color: #009900;">&#40;</span>clamp<span style="color: #009900;">&#40;</span><span style="color:#800080;">1.0</span> <span style="color: #339933;">-</span> diff <span style="color: #339933;">/</span> range<span style="color: #339933;">,</span> <span style="color:#800080;">0.0</span><span style="color: #339933;">,</span> <span style="color:#800080;">1.0</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">*</span> <span style="color:#800080;">90.0</span> <span style="color: #339933;">*</span> <span style="color:#800080;">3.14159</span> <span style="color: #339933;">/</span> <span style="color:#800080;">180.0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        s <span style="color: #339933;">=</span> clamp<span style="color: #009900;">&#40;</span>s<span style="color: #339933;">,</span> <span style="color:#800080;">0.0</span><span style="color: #339933;">,</span> <span style="color:#800080;">1.0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>s <span style="color: #339933;">==</span> <span style="color:#800080;">0.0</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            r <span style="color: #339933;">=</span> g <span style="color: #339933;">=</span> b <span style="color: #339933;">=</span> v<span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
            h <span style="color: #339933;">/=</span> <span style="color:#800080;">60.0</span><span style="color: #339933;">;</span>
            <span style="color: #993333;">int</span> i <span style="color: #339933;">=</span> <span style="color: #993333;">int</span><span style="color: #009900;">&#40;</span>floor<span style="color: #009900;">&#40;</span>h<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            f <span style="color: #339933;">=</span> h <span style="color: #339933;">-</span> <span style="color: #993333;">float</span><span style="color: #009900;">&#40;</span>i<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
            p <span style="color: #339933;">=</span> v <span style="color: #339933;">*</span> <span style="color: #009900;">&#40;</span> <span style="color:#800080;">1.0</span> <span style="color: #339933;">-</span> s <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            q <span style="color: #339933;">=</span> v <span style="color: #339933;">*</span> <span style="color: #009900;">&#40;</span> <span style="color:#800080;">1.0</span> <span style="color: #339933;">-</span> s <span style="color: #339933;">*</span> f <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            t <span style="color: #339933;">=</span> v <span style="color: #339933;">*</span> <span style="color: #009900;">&#40;</span> <span style="color:#800080;">1.0</span> <span style="color: #339933;">-</span> s <span style="color: #339933;">*</span> <span style="color: #009900;">&#40;</span> <span style="color:#800080;">1.0</span> <span style="color: #339933;">-</span> f <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
            <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>i <span style="color: #339933;">==</span> <span style="color: #0000dd;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                r <span style="color: #339933;">=</span> v<span style="color: #339933;">;</span> g <span style="color: #339933;">=</span> t<span style="color: #339933;">;</span> b <span style="color: #339933;">=</span> p<span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>i <span style="color: #339933;">==</span> <span style="color: #0000dd;">1</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                r <span style="color: #339933;">=</span> q<span style="color: #339933;">;</span> g <span style="color: #339933;">=</span> v<span style="color: #339933;">;</span> b <span style="color: #339933;">=</span> p<span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>i <span style="color: #339933;">==</span> <span style="color: #0000dd;">2</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                r <span style="color: #339933;">=</span> p<span style="color: #339933;">;</span> g <span style="color: #339933;">=</span> v<span style="color: #339933;">;</span> b <span style="color: #339933;">=</span> t<span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>i <span style="color: #339933;">==</span> <span style="color: #0000dd;">3</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                r <span style="color: #339933;">=</span> p<span style="color: #339933;">;</span> g <span style="color: #339933;">=</span> q<span style="color: #339933;">;</span> b <span style="color: #339933;">=</span> v<span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>i <span style="color: #339933;">==</span> <span style="color: #0000dd;">4</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                r <span style="color: #339933;">=</span> t<span style="color: #339933;">;</span> g <span style="color: #339933;">=</span> p<span style="color: #339933;">;</span> b <span style="color: #339933;">=</span> v<span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>i <span style="color: #339933;">==</span> <span style="color: #0000dd;">5</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                r <span style="color: #339933;">=</span> v<span style="color: #339933;">;</span> g <span style="color: #339933;">=</span> p<span style="color: #339933;">;</span> b <span style="color: #339933;">=</span> q<span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
        dst <span style="color: #339933;">=</span> pixel4<span style="color: #009900;">&#40;</span>r<span style="color: #339933;">,</span> g<span style="color: #339933;">,</span> b<span style="color: #339933;">,</span> inputColor.<span style="color: #202020;">a</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>實際拿一張色彩豐富的照片來試試看<br />
(照片為印度孟買某學校外)</p>
<p><a href="http://blog-uploads.richmediaplus.com/2011/09/DSCN0140.jpg"><img src="http://blog-uploads.richmediaplus.com/2011/09/DSCN0140-300x225.jpg" alt="" title="DSCN0140" width="300" height="225" class="alignnone size-medium wp-image-823" /></a></p>
<p>照片下方特別加上了色條，比較容易看出不同 Hue 值與抽色濾鏡的效果關係</p>
<p>Partial Color Shader 線上範例：</p>
<p>
<object width="500" height="400">
<param name="movie" value="http://blog-uploads.richmediaplus.com/2011/09/PartialColorShader2.swf"></param>
<param name="quality" value="high"></param>
<param name="wmode" value="window"></param>
<param name="menu" value="false"></param>
<param name="bgcolor" value="#FFFFFF"></param>
<param name="allowScriptAccess" value="always"></param>
<embed type="application/x-shockwave-flash" width="500" height="400" src="http://blog-uploads.richmediaplus.com/2011/09/PartialColorShader2.swf" quality="high" bgcolor="#FFFFFF" wmode="window" menu="false" ></embed>
</object>
</p>
<p><a href="https://sites.google.com/site/riafiles/PartialColorShader2.zip?attredirects=0&#038;d=1">Partial Color Shader 原始檔案下載</a></p>
<p>Related posts:<ol>
<li><a href='http://blog.richmediaplus.com/2009/07/virtual-unique-urls-for-flex-flash/' rel='bookmark' title='Virtual Unique URLs for Flex/Flash'>Virtual Unique URLs for Flex/Flash</a></li>
<li><a href='http://blog.richmediaplus.com/2011/06/avoid-flash-blend-mode-issue/' rel='bookmark' title='Flash 混色模式的問題與解決方式'>Flash 混色模式的問題與解決方式</a></li>
<li><a href='http://blog.richmediaplus.com/2011/07/timeline-placed-video-smoothing/' rel='bookmark' title='Flash 影格預置 Video 抗鋸齒功能'>Flash 影格預置 Video 抗鋸齒功能</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://blog.richmediaplus.com/2011/09/partial-color-shader/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

