<?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/category/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>Andoird Launcher AIR App</title>
		<link>http://blog.richmediaplus.com/2011/11/andoird-launcher-air-app/</link>
		<comments>http://blog.richmediaplus.com/2011/11/andoird-launcher-air-app/#comments</comments>
		<pubDate>Sun, 20 Nov 2011 15:43:25 +0000</pubDate>
		<dc:creator>milkmidi</dc:creator>
				<category><![CDATA[ActionScript3]]></category>
		<category><![CDATA[Air]]></category>
		<category><![CDATA[Android]]></category>
		<category><![CDATA[Flash]]></category>

		<guid isPermaLink="false">http://blog.richmediaplus.com/?p=891</guid>
		<description><![CDATA[大家好，我是奶綠茶 最近案子的需要，所以會用 Android 和 AIR 來混搭開發 app 遇到的問題有： 1.Android 怎麼啟動另一個 App(Andoird or AIR) ? 2.啟動後，如何帶變數過去? 3.反過來 AIR 啟動 Andoird 且帶值? 先了解 Android 怎麼啟動另一個 App. 使用 Intent 類別, 且指定要啟動的 app package路徑 Intent intent = new Intent&#40; Intent.ACTION_MAIN , null&#41;; intent.addCategory&#40; Intent.CATEGORY_LAUNCHER&#41;; final ComponentName cn = new ComponentName&#40;&#34;com.android.settings&#34;, &#34;com.android.settings.fuelgauge.PowerUsageSummary&#34;&#41;; intent.setComponent&#40;cn&#41;; startActivity&#40;intent&#41;; 如果是要啟動 AIR 的 app. 就要在 package [...]
Related posts:<ol>
<li><a href='http://blog.richmediaplus.com/2011/11/android-killprocess/' rel='bookmark' title='Android killProcess'>Android killProcess</a></li>
<li><a href='http://blog.richmediaplus.com/2011/11/flash-in-android-webview/' rel='bookmark' title='Flash in Android WebView'>Flash in Android WebView</a></li>
<li><a href='http://blog.richmediaplus.com/2009/06/flashplayer-10-android/' rel='bookmark' title='Flashplayer 10 率先登陸 Android!'>Flashplayer 10 率先登陸 Android!</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>大家好，我是奶綠茶<br />
最近案子的需要，所以會用 Android 和 AIR 來混搭開發 app<br />
遇到的問題有：<br />
1.Android 怎麼啟動另一個 App(Andoird or AIR) ?<br />
2.啟動後，如何帶變數過去?<br />
3.反過來 AIR 啟動 Andoird 且帶值?<br />
先了解 Android 怎麼啟動另一個 App.<br />
使用 Intent 類別, 且指定要啟動的 app package路徑</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">Intent intent <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Intent<span style="color: #009900;">&#40;</span> Intent.<span style="color: #006633;">ACTION_MAIN</span> , <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
intent.<span style="color: #006633;">addCategory</span><span style="color: #009900;">&#40;</span> Intent.<span style="color: #006633;">CATEGORY_LAUNCHER</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">final</span> ComponentName cn <span style="color: #339933;">=</span> 
<span style="color: #000000; font-weight: bold;">new</span> ComponentName<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;com.android.settings&quot;</span>, <span style="color: #0000ff;">&quot;com.android.settings.fuelgauge.PowerUsageSummary&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
intent.<span style="color: #006633;">setComponent</span><span style="color: #009900;">&#40;</span>cn<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
startActivity<span style="color: #009900;">&#40;</span>intent<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>如果是要啟動 AIR 的 app. 就要在 package 前加上 air.<br />
new ComponentName(“air.com.android.settings”, “air.com.android.settings.fuelgauge.PowerUsageSummary”);<br />
第二個問題是啟動後，如何帶變數過去?<br />
只要在 intent 使用 putExtra 即可 intent.putExtra(“Key”, “Value”);<br />
接收的 Activity 在 onCreate();<br />
使用 getIntent().getExtras().getString(“Key”);<br />
但在 AIR 的部份，無法修改 onCreate ,所以只好找另外的方法。<br />
好在 Android 的機制裡，可以使用 scheme 的方法呼叫, 像 market:// 這樣，<br />
當遇到這樣的連結時，只要 app 有在 mainfest 設定 intent-filter 的話，就會啟動該 app.<br />
在這我們以：testapp:// 為例 Android 端：</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">Uri uri <span style="color: #339933;">=</span> Uri.<span style="color: #006633;">parse</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;testapp://com.example/milkmidi/tesetdata&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
intent <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Intent<span style="color: #009900;">&#40;</span> Intent.<span style="color: #006633;">ACTION_VIEW</span>, uri<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>AIR 端：在 application.xml 裡加上 ＜data android:scheme=”testapp” android:host=”com.example” /＞<br />
當遇到是 testapp://com.example 這樣的連結時，就可以啟動 AIR 的 app.</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;">＜android＞
 ＜manifestAdditions＞＜![CDATA[
&nbsp;
  ＜manifest android:installLocation=&quot;auto&quot;＞    
&nbsp;
   ＜application＞ 
    ＜activity ＞ 
     ＜intent-filter＞
      ＜action android:name=&quot;android.intent.action.MAIN&quot;/＞
      ＜category android:name=&quot;android.intent.category.LAUNCHER&quot;/＞
     ＜/intent-filter＞
     ＜intent-filter＞
      ＜action android:name=&quot;android.intent.action.VIEW&quot;/＞
      ＜category android:name=&quot;android.intent.category.BROWSABLE&quot;/＞
      ＜category android:name=&quot;android.intent.category.DEFAULT&quot;/＞
      ＜data android:scheme=&quot;testapp&quot; android:host=&quot;com.example&quot; /＞
     ＜/intent-filter＞
    ＜/activity＞ 
   ＜/application＞     
&nbsp;
  ＜/manifest＞
&nbsp;
 ]]＞＜/manifestAdditions＞
＜/android＞</pre></div></div>

<p>得到變數可以使用：</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;">NativeApplication<span style="color: #000066; font-weight: bold;">.</span>nativeApplication<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span>
     InvokeEvent<span style="color: #000066; font-weight: bold;">.</span>INVOKE<span style="color: #000066; font-weight: bold;">,</span> onInvoke<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> onInvoke<span style="color: #000000;">&#40;</span>e<span style="color: #000066; font-weight: bold;">:</span>InvokeEvent<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;">log</span><span style="color: #000000;">&#40;</span> <span style="color: #990000;">&quot;onInvoke:&quot;</span> <span style="color: #000066; font-weight: bold;">+</span> e<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">arguments</span> <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
  <span style="color: #000000;">&#125;</span></pre></div></div>

<p>參考文章：</p>
<p>http://www.riaspace.com/2011/08/defining-custom-url-schemes-for-your-air-mobile-applications</p>
<p>http://stackoverflow.com/questions/5591086/passing-parameters-from-a-java-activity-to-adobe-air-app</p>
<p>http://www.slideshare.net/CodeAndroid/android-intent-intent-filter-broadcast-receivers</p>
<p>Related posts:<ol>
<li><a href='http://blog.richmediaplus.com/2011/11/android-killprocess/' rel='bookmark' title='Android killProcess'>Android killProcess</a></li>
<li><a href='http://blog.richmediaplus.com/2011/11/flash-in-android-webview/' rel='bookmark' title='Flash in Android WebView'>Flash in Android WebView</a></li>
<li><a href='http://blog.richmediaplus.com/2009/06/flashplayer-10-android/' rel='bookmark' title='Flashplayer 10 率先登陸 Android!'>Flashplayer 10 率先登陸 Android!</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://blog.richmediaplus.com/2011/11/andoird-launcher-air-app/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Adobe AIR ServerSocket</title>
		<link>http://blog.richmediaplus.com/2011/11/adobe-air-serversocket-2/</link>
		<comments>http://blog.richmediaplus.com/2011/11/adobe-air-serversocket-2/#comments</comments>
		<pubDate>Sun, 20 Nov 2011 15:37:54 +0000</pubDate>
		<dc:creator>milkmidi</dc:creator>
				<category><![CDATA[ActionScript3]]></category>
		<category><![CDATA[Air]]></category>
		<category><![CDATA[Android]]></category>

		<guid isPermaLink="false">http://blog.richmediaplus.com/?p=889</guid>
		<description><![CDATA[大家好，我是奶綠茶 今天來介紹一下 Adobe AIR ServerSocket 需求： 很多台電腦，在同一個區網，要能彼此溝通，同時 Android 平版也要能傳接值。 解： 本來想如果就只有單 flash 的話, 可以使用 P2P 區網連線就決解了， 但因為 Andriod 平版也要能支援, 所以就改成 Socket 來溝通。 那為什麼不用 Java 架 Socket Server 就好了，因為我是閃客(因為用 Java 做動畫會死人) AIR 端，使用ServerSocket 類別。 在畫面上就只放所有連線的 Client 列表，一個發送訊息的文字和Button, 一個接收的文字 &#60;?xml version=&#34;1.0&#34; encoding=&#34;utf-8&#34;?&#62; &#60;s:WindowedApplication xmlns:fx=&#34;http://ns.adobe.com/mxml/2009&#34; xmlns:s=&#34;library://ns.adobe.com/flex/spark&#34; xmlns:mx=&#34;library://ns.adobe.com/flex/mx&#34; creationComplete=&#34;createComplete(event);&#34; close=&#34;appCloseHandler()&#34;&#62; &#160; &#60;fx:Declarations&#62; &#60;!-- Place non-visual elements (e.g., services, value [...]
Related posts:<ol>
<li><a href='http://blog.richmediaplus.com/2011/11/andoird-launcher-air-app/' rel='bookmark' title='Andoird Launcher AIR App'>Andoird Launcher AIR App</a></li>
<li><a href='http://blog.richmediaplus.com/2011/11/android-killprocess/' rel='bookmark' title='Android killProcess'>Android killProcess</a></li>
<li><a href='http://blog.richmediaplus.com/2010/02/adobe-air-on-android/' rel='bookmark' title='Adobe Air on Android'>Adobe Air on Android</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>大家好，我是奶綠茶<br />
今天來介紹一下 Adobe AIR ServerSocket<br />
需求：<br />
很多台電腦，在同一個區網，要能彼此溝通，同時 Android 平版也要能傳接值。<br />
解：<br />
本來想如果就只有單 flash 的話, 可以使用 P2P 區網連線就決解了，<br />
但因為 Andriod 平版也要能支援, 所以就改成 Socket 來溝通。</p>
<p>那為什麼不用 Java 架 Socket Server 就好了，因為我是閃客(因為用 Java 做動畫會死人)<br />
AIR 端，使用ServerSocket 類別。<br />
在畫面上就只放所有連線的 Client 列表，一個發送訊息的文字和Button, 一個接收的文字</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:WindowedApplication</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;">        creationComplete=<span style="color: #ff0000;">&quot;createComplete(event);&quot;</span></span>
<span style="color: #000000;">        close=<span style="color: #ff0000;">&quot;appCloseHandler()&quot;</span><span style="color: #7400FF;">&gt;</span></span>
&nbsp;
 <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: #808080; font-style: italic;">&lt;!-- Place non-visual elements (e.g., services, value objects) here --&gt;</span></span>
 <span style="color: #000000;"><span style="color: #7400FF;">&lt;/fx:Declarations</span><span style="color: #7400FF;">&gt;</span></span>
&nbsp;
 <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 flash.display.NativeWindow;</span>
<span style="color: #000000;">  import flash.events.Event;</span>
<span style="color: #000000;">  import flash.events.ProgressEvent;</span>
<span style="color: #000000;">  import flash.events.ServerSocketConnectEvent;</span>
<span style="color: #000000;">  import flash.net.ServerSocket;</span>
<span style="color: #000000;">  import flash.net.Socket;</span>
<span style="color: #000000;">  import flash.utils.ByteArray;</span>
<span style="color: #000000;">  import mx.collections.ArrayCollection;</span>
<span style="color: #000000;">  import mx.controls.Alert;</span>
<span style="color: #000000;">  import mx.events.FlexEvent;</span>
&nbsp;
&nbsp;
<span style="color: #000000;">  private var server :ServerSocket = new ServerSocket<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;</span>
&nbsp;
<span style="color: #000000;">  <span style="color: #66cc66;">&#91;</span>Bindable<span style="color: #66cc66;">&#93;</span></span>
<span style="color: #000000;">  private var serverActivity:Boolean = false;</span>
&nbsp;
<span style="color: #000000;">  <span style="color: #66cc66;">&#91;</span>Bindable<span style="color: #66cc66;">&#93;</span></span>
<span style="color: #000000;">  private var clientSockets:ArrayCollection = new ArrayCollection<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;</span>
&nbsp;
<span style="color: #000000;">  //private var ipAddress  :String = <span style="color: #ff0000;">&quot;192.168.253.176&quot;</span>;</span>
<span style="color: #000000;">  private var ipAddress  :String = <span style="color: #ff0000;">&quot;127.0.0.1&quot;</span>;</span>
<span style="color: #000000;">  private var ipAddressPort :int = <span style="color: #cc66cc;">9527</span>;</span>
&nbsp;
<span style="color: #000000;">  private function createComplete<span style="color: #66cc66;">&#40;</span>e:FlexEvent<span style="color: #66cc66;">&#41;</span>:void <span style="color: #66cc66;">&#123;</span>   </span>
&nbsp;
<span style="color: #000000;">   try <span style="color: #66cc66;">&#123;</span></span>
<span style="color: #000000;">    server.bind<span style="color: #66cc66;">&#40;</span>ipAddressPort, ipAddress<span style="color: #66cc66;">&#41;</span>;</span>
<span style="color: #000000;">    log<span style="color: #66cc66;">&#40;</span> <span style="color: #ff0000;">&quot;bind:&quot;</span> + ipAddress+<span style="color: #ff0000;">&quot;:&quot;</span>+ipAddressPort <span style="color: #66cc66;">&#41;</span>;</span>
<span style="color: #000000;">    server.addEventListener<span style="color: #66cc66;">&#40;</span>ServerSocketConnectEvent.CONNECT , clientConnectedHandler<span style="color: #66cc66;">&#41;</span>;   </span>
<span style="color: #000000;">    server.listen<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;</span>
<span style="color: #000000;">    serverActivity = true;</span>
<span style="color: #000000;">   <span style="color: #66cc66;">&#125;</span>catch <span style="color: #66cc66;">&#40;</span>err:Error<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span></span>
<span style="color: #000000;">    log<span style="color: #66cc66;">&#40;</span> err + <span style="color: #ff0000;">&quot;&quot;</span> <span style="color: #66cc66;">&#41;</span>;</span>
<span style="color: #000000;">    serverActivity = false;</span>
<span style="color: #000000;">    Alert.show<span style="color: #66cc66;">&#40;</span>err.message<span style="color: #66cc66;">&#41;</span>;    </span>
<span style="color: #000000;">   <span style="color: #66cc66;">&#125;</span>   </span>
<span style="color: #000000;">  <span style="color: #66cc66;">&#125;</span></span>
&nbsp;
<span style="color: #000000;">  private function clientConnectedHandler<span style="color: #66cc66;">&#40;</span>e:ServerSocketConnectEvent<span style="color: #66cc66;">&#41;</span>:void <span style="color: #66cc66;">&#123;</span></span>
<span style="color: #000000;">   //每當有新的 Client 連該進來, 就會觸發該函式。</span>
<span style="color: #000000;">   var clientSocket:Socket = e.socket;</span>
<span style="color: #000000;">   log<span style="color: #66cc66;">&#40;</span> clientSocket.localAddress + <span style="color: #ff0000;">&quot;:&quot;</span> + clientSocket.localPort <span style="color: #66cc66;">&#41;</span>;</span>
<span style="color: #000000;">   clientSockets.addItem<span style="color: #66cc66;">&#40;</span> clientSocket <span style="color: #66cc66;">&#41;</span>;</span>
<span style="color: #000000;">   clientSocket.addEventListener<span style="color: #66cc66;">&#40;</span>Event.CLOSE , clientDisconnectedHandler<span style="color: #66cc66;">&#41;</span>;</span>
<span style="color: #000000;">   //偵聽當 Client 離線時。</span>
<span style="color: #000000;">   clientSocket.addEventListener<span style="color: #66cc66;">&#40;</span>ProgressEvent.SOCKET_DATA, onClientSocketData <span style="color: #66cc66;">&#41;</span>;</span>
<span style="color: #000000;">   //偵聽 Client 發出的訊息</span>
<span style="color: #000000;">  <span style="color: #66cc66;">&#125;</span></span>
&nbsp;
<span style="color: #000000;">  private function onClientSocketData<span style="color: #66cc66;">&#40;</span>e:ProgressEvent<span style="color: #66cc66;">&#41;</span>:void <span style="color: #66cc66;">&#123;</span></span>
<span style="color: #000000;">   // 讀取 Client 發出的訊息</span>
<span style="color: #000000;">   var buffer:ByteArray = new ByteArray<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;</span>
<span style="color: #000000;">   var clientSocket:Socket = e.currentTarget as Socket;</span>
<span style="color: #000000;">            clientSocket.readBytes<span style="color: #66cc66;">&#40;</span> buffer, <span style="color: #cc66cc;">0</span>, clientSocket.bytesAvailable <span style="color: #66cc66;">&#41;</span>;</span>
<span style="color: #000000;">            log<span style="color: #66cc66;">&#40;</span> <span style="color: #ff0000;">&quot;Received: &quot;</span> + buffer.toString<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#41;</span>;   </span>
<span style="color: #000000;">  <span style="color: #66cc66;">&#125;</span></span>
&nbsp;
<span style="color: #000000;">  private function clientDisconnectedHandler<span style="color: #66cc66;">&#40;</span>e:Event<span style="color: #66cc66;">&#41;</span>:void <span style="color: #66cc66;">&#123;</span></span>
<span style="color: #000000;">   // 當 Client 離線時。</span>
<span style="color: #000000;">   e.currentTarget.removeEventListener<span style="color: #66cc66;">&#40;</span> e.type , arguments.callee <span style="color: #66cc66;">&#41;</span>;</span>
<span style="color: #000000;">   clientSockets.removeItemAt<span style="color: #66cc66;">&#40;</span> clientSockets.getItemIndex<span style="color: #66cc66;">&#40;</span>e.target<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;</span>
<span style="color: #000000;">  <span style="color: #66cc66;">&#125;</span></span>
<span style="color: #000000;">  private function log<span style="color: #66cc66;">&#40;</span>o:Object<span style="color: #66cc66;">&#41;</span>:void <span style="color: #66cc66;">&#123;</span></span>
<span style="color: #000000;">   textArea.text += o +<span style="color: #ff0000;">&quot;\n&quot;</span>;</span>
<span style="color: #000000;">  <span style="color: #66cc66;">&#125;</span></span>
&nbsp;
<span style="color: #000000;">  private function writeDataToSockets<span style="color: #66cc66;">&#40;</span>e:Event<span style="color: #66cc66;">&#41;</span>:void <span style="color: #66cc66;">&#123;</span></span>
<span style="color: #000000;">   var msg:String = textInput.text;</span>
<span style="color: #000000;">   if <span style="color: #66cc66;">&#40;</span>msg == <span style="color: #ff0000;">&quot;&quot;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span></span>
<span style="color: #000000;">    return;</span>
<span style="color: #000000;">   <span style="color: #66cc66;">&#125;</span>   </span>
<span style="color: #000000;">   trace<span style="color: #66cc66;">&#40;</span> <span style="color: #ff0000;">&quot;ServerSocketMain.writeDataToSockets &quot;</span><span style="color: #66cc66;">&#41;</span>;</span>
<span style="color: #000000;">   // 對所有的 Client 發出訊息。</span>
<span style="color: #000000;">   for each <span style="color: #66cc66;">&#40;</span>var socket:Socket in clientSockets<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span></span>
<span style="color: #000000;">    if <span style="color: #66cc66;">&#40;</span>socket.connected<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>     </span>
<span style="color: #000000;">     try <span style="color: #66cc66;">&#123;</span></span>
<span style="color: #000000;">      socket.writeUTF<span style="color: #66cc66;">&#40;</span>msg<span style="color: #66cc66;">&#41;</span>;</span>
<span style="color: #000000;">      socket.flush<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;</span>
<span style="color: #000000;">     <span style="color: #66cc66;">&#125;</span>catch <span style="color: #66cc66;">&#40;</span>err:Error<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span></span>
<span style="color: #000000;">      log<span style="color: #66cc66;">&#40;</span>err<span style="color: #66cc66;">&#41;</span>;</span>
<span style="color: #000000;">     <span style="color: #66cc66;">&#125;</span>     </span>
<span style="color: #000000;">    <span style="color: #66cc66;">&#125;</span></span>
<span style="color: #000000;">   <span style="color: #66cc66;">&#125;</span></span>
<span style="color: #000000;">  <span style="color: #66cc66;">&#125;</span></span>
<span style="color: #000000;">  private function appCloseHandler<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:void <span style="color: #66cc66;">&#123;</span>  </span>
<span style="color: #000000;">   server.close<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;</span>
<span style="color: #000000;">   server = null;   </span>
<span style="color: #000000;">  <span style="color: #66cc66;">&#125;</span> </span>
&nbsp;
&nbsp;
<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:HGroup</span> width=<span style="color: #ff0000;">&quot;100%&quot;</span> height=<span style="color: #ff0000;">&quot;100%&quot;</span> paddingLeft=<span style="color: #ff0000;">&quot;5&quot;</span><span style="color: #7400FF;">&gt;</span></span>
  <span style="color: #000000;"><span style="color: #7400FF;">&lt;s:List</span> width=<span style="color: #ff0000;">&quot;200&quot;</span> height=<span style="color: #ff0000;">&quot;100%&quot;</span> dataProvider=<span style="color: #ff0000;">&quot;{clientSockets}&quot;</span> labelField=<span style="color: #ff0000;">&quot;localAddress&quot;</span><span style="color: #7400FF;">&gt;</span><span style="color: #7400FF;">&lt;/s:List</span><span style="color: #7400FF;">&gt;</span></span>
&nbsp;
  <span style="color: #000000;"><span style="color: #7400FF;">&lt;s:VGroup</span> 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:HGroup</span> width=<span style="color: #ff0000;">&quot;600&quot;</span><span style="color: #7400FF;">&gt;</span></span>
    <span style="color: #000000;"><span style="color: #7400FF;">&lt;s:TextInput</span> id=<span style="color: #ff0000;">&quot;textInput&quot;</span> width=<span style="color: #ff0000;">&quot;200&quot;</span> text=<span style="color: #ff0000;">&quot;server send info to all client&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
    <span style="color: #000000;"><span style="color: #7400FF;">&lt;s:Button</span> x=<span style="color: #ff0000;">&quot;130&quot;</span> y=<span style="color: #ff0000;">&quot;10&quot;</span> label=<span style="color: #ff0000;">&quot;Send&quot;</span> </span>
<span style="color: #000000;">     click=<span style="color: #ff0000;">&quot;writeDataToSockets(event)&quot;</span> </span>
<span style="color: #000000;">     enabled=<span style="color: #ff0000;">&quot;{textInput.text.length&gt;</span></span>0}&quot; visible=&quot;{clientSockets.length&gt;0}&quot; /&gt;
   <span style="color: #000000;"><span style="color: #7400FF;">&lt;/s:HGroup</span><span style="color: #7400FF;">&gt;</span></span> 
   <span style="color: #000000;"><span style="color: #7400FF;">&lt;s:Button</span> label=<span style="color: #ff0000;">&quot;clear&quot;</span> click=<span style="color: #ff0000;">&quot;{textArea.text=''}&quot;</span> enabled=<span style="color: #ff0000;">&quot;{serverActivity}&quot;</span><span style="color: #7400FF;">/&gt;</span></span>
   <span style="color: #000000;"><span style="color: #7400FF;">&lt;s:TextArea</span> id=<span style="color: #ff0000;">&quot;textArea&quot;</span> width=<span style="color: #ff0000;">&quot;200&quot;</span> height=<span style="color: #ff0000;">&quot;100%&quot;</span> editable=<span style="color: #ff0000;">&quot;false&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
  <span style="color: #000000;"><span style="color: #7400FF;">&lt;/s:VGroup</span><span style="color: #7400FF;">&gt;</span></span>
 <span style="color: #000000;"><span style="color: #7400FF;">&lt;/s:HGroup</span><span style="color: #7400FF;">&gt;</span></span> 
<span style="color: #000000;"><span style="color: #7400FF;">&lt;/s:WindowedApplication</span><span style="color: #7400FF;">&gt;</span></span></pre></div></div>

<p>在用 flash 寫一個 Client 端測試：</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/halo&quot;</span></span>
<span style="color: #000000;">      creationComplete=<span style="color: #ff0000;">&quot;createSocket(event)&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:VerticalLayout</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;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 flash.events.Event;</span>
<span style="color: #000000;">   import flash.events.ProgressEvent;</span>
<span style="color: #000000;">   import flash.net.Socket;</span>
<span style="color: #000000;">   import mx.events.FlexEvent;</span>
&nbsp;
<span style="color: #000000;">   protected var socket:Socket;</span>
&nbsp;
<span style="color: #000000;">   private var ipAddress  :String = <span style="color: #ff0000;">&quot;127.0.0.1&quot;</span>;</span>
<span style="color: #000000;">   private var ipAddressPort :int = <span style="color: #cc66cc;">9527</span>;</span>
&nbsp;
<span style="color: #000000;">   protected function createSocket<span style="color: #66cc66;">&#40;</span>event:FlexEvent<span style="color: #66cc66;">&#41;</span>:void <span style="color: #66cc66;">&#123;</span>    </span>
<span style="color: #000000;">    socket = new Socket<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;</span>
<span style="color: #000000;">    socket.addEventListener<span style="color: #66cc66;">&#40;</span>Event.CONNECT,socketConnected<span style="color: #66cc66;">&#41;</span>;</span>
<span style="color: #000000;">    socket.addEventListener<span style="color: #66cc66;">&#40;</span>ProgressEvent.SOCKET_DATA, socketData<span style="color: #66cc66;">&#41;</span>;      </span>
<span style="color: #000000;">    socket.connect<span style="color: #66cc66;">&#40;</span> ipAddress, ipAddressPort <span style="color: #66cc66;">&#41;</span>;    </span>
<span style="color: #000000;">   <span style="color: #66cc66;">&#125;</span>   </span>
<span style="color: #000000;">   protected function socketConnected<span style="color: #66cc66;">&#40;</span>e:Event<span style="color: #66cc66;">&#41;</span>:void<span style="color: #66cc66;">&#123;</span></span>
<span style="color: #000000;">    log<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;client - socket connected&quot;</span><span style="color: #66cc66;">&#41;</span>;</span>
<span style="color: #000000;">   <span style="color: #66cc66;">&#125;</span>   </span>
<span style="color: #000000;">   protected function socketData<span style="color: #66cc66;">&#40;</span>e:ProgressEvent<span style="color: #66cc66;">&#41;</span>:void<span style="color: #66cc66;">&#123;</span></span>
<span style="color: #000000;">    trace<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;client - socket data&quot;</span><span style="color: #66cc66;">&#41;</span>;</span>
<span style="color: #000000;">    //trace<span style="color: #66cc66;">&#40;</span>socket.readUTF<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;    </span>
<span style="color: #000000;">    log<span style="color: #66cc66;">&#40;</span>socket.readUTF<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;    </span>
<span style="color: #000000;">   <span style="color: #66cc66;">&#125;</span>   </span>
<span style="color: #000000;">   private function callServerClickHandler<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:void <span style="color: #66cc66;">&#123;</span></span>
<span style="color: #000000;">    try <span style="color: #66cc66;">&#123;</span></span>
<span style="color: #000000;">     socket.writeUTF<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;callServer&quot;</span><span style="color: #66cc66;">&#41;</span>;</span>
<span style="color: #000000;">     socket.flush<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;</span>
<span style="color: #000000;">    <span style="color: #66cc66;">&#125;</span>catch <span style="color: #66cc66;">&#40;</span>err:Error<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span></span>
<span style="color: #000000;">     log<span style="color: #66cc66;">&#40;</span>err<span style="color: #66cc66;">&#41;</span>;</span>
<span style="color: #000000;">    <span style="color: #66cc66;">&#125;</span></span>
&nbsp;
<span style="color: #000000;">   <span style="color: #66cc66;">&#125;</span></span>
<span style="color: #000000;">   private function log<span style="color: #66cc66;">&#40;</span>o:Object<span style="color: #66cc66;">&#41;</span>:void <span style="color: #66cc66;">&#123;</span></span>
<span style="color: #000000;">    textArea.text += o + <span style="color: #ff0000;">&quot;\n&quot;</span>;</span>
<span style="color: #000000;">   <span style="color: #66cc66;">&#125;</span></span>
&nbsp;
<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:Button</span> label=<span style="color: #ff0000;">&quot;call Server&quot;</span> click=<span style="color: #ff0000;">&quot;callServerClickHandler()&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
 <span style="color: #000000;"><span style="color: #7400FF;">&lt;s:TextArea</span> id=<span style="color: #ff0000;">&quot;textArea&quot;</span><span style="color: #7400FF;">&gt;</span><span style="color: #7400FF;">&lt;/s:TextArea</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>Java/Android 端<br />
使用 Socket 類別<br />
因為程式碼落落長，<br />
有需要的朋友就直接下載 Android 端的程式碼，在這就不貼出來了</p>
<p><a href="http://dl.dropbox.com/u/2069696/blog/2011_10_28_socket/2011_10_28_ServerSocketDemo_AIR.zip">AIR</a><br />
<a href="http://dl.dropbox.com/u/2069696/blog/2011_10_28_socket/2011_10_28_ServerSocketDemo_Java.zip">Java/Android</a></p>
<p>Related posts:<ol>
<li><a href='http://blog.richmediaplus.com/2011/11/andoird-launcher-air-app/' rel='bookmark' title='Andoird Launcher AIR App'>Andoird Launcher AIR App</a></li>
<li><a href='http://blog.richmediaplus.com/2011/11/android-killprocess/' rel='bookmark' title='Android killProcess'>Android killProcess</a></li>
<li><a href='http://blog.richmediaplus.com/2010/02/adobe-air-on-android/' rel='bookmark' title='Adobe Air on Android'>Adobe Air on Android</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://blog.richmediaplus.com/2011/11/adobe-air-serversocket-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>簡易版 3D Banner 效果</title>
		<link>http://blog.richmediaplus.com/2011/11/%e7%b0%a1%e6%98%93%e7%89%88-3d-banner-%e6%95%88%e6%9e%9c/</link>
		<comments>http://blog.richmediaplus.com/2011/11/%e7%b0%a1%e6%98%93%e7%89%88-3d-banner-%e6%95%88%e6%9e%9c/#comments</comments>
		<pubDate>Sun, 20 Nov 2011 15:27:24 +0000</pubDate>
		<dc:creator>milkmidi</dc:creator>
				<category><![CDATA[ActionScript3]]></category>
		<category><![CDATA[Flash]]></category>

		<guid isPermaLink="false">http://blog.richmediaplus.com/?p=887</guid>
		<description><![CDATA[大家好，我是奶綠茶 最近學生問起了一個 3D 的 Banner 效果要如何製作 寫了一個簡單的 Demo, 程式碼也很短， 只用到 TweenMax , 和 FlashPlayer10 的 3D 即可做到 import com.greensock.TweenMax; var container:Sprite = new Sprite&#40;&#41;; container.x = stage.stageWidth &#38;gt;&#38;gt; 1; addChild&#40; container &#41;; addEventListener&#40;Event.ENTER_FRAME , enterFrameHandler&#41;; &#160; var back:MovieClip = new Back_mc; back.x = stage.stageWidth &#38;gt;&#38;gt;1; back.y = 40; back.visible=false; &#160; addChild&#40; back &#41;; &#160; back.addEventListener&#40;MouseEvent.CLICK [...]
Related posts:<ol>
<li><a href='http://blog.richmediaplus.com/2011/05/bitmap-smooth-slow-motion-tip/' rel='bookmark' title='點陣圖慢速平滑移動技巧'>點陣圖慢速平滑移動技巧</a></li>
<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/2009/12/as3-project-custom-preload-load-application/' rel='bookmark' title='AS3工程 Custom Preloader 動態加載 Application'>AS3工程 Custom Preloader 動態加載 Application</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>大家好，我是奶綠茶<br />
最近學生問起了一個 3D 的 Banner 效果要如何製作<br />
寫了一個簡單的 Demo, 程式碼也很短，<br />
只用到 TweenMax , 和 FlashPlayer10 的 3D 即可做到</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #0033ff; font-weight: bold;">import</span> com<span style="color: #000066; font-weight: bold;">.</span>greensock<span style="color: #000066; font-weight: bold;">.</span>TweenMax<span style="color: #000066; font-weight: bold;">;</span>
<span style="color: #6699cc; font-weight: bold;">var</span> container<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Sprite</span> = <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">Sprite</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
container<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">x</span> = <span style="color: #004993;">stage</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">stageWidth</span> <span style="color: #000066; font-weight: bold;">&amp;</span>gt<span style="color: #000066; font-weight: bold;">;&amp;</span>gt<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: #004993;">addChild</span><span style="color: #000000;">&#40;</span> container <span style="color: #000000;">&#41;</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;">ENTER_FRAME</span> <span style="color: #000066; font-weight: bold;">,</span> enterFrameHandler<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
<span style="color: #6699cc; font-weight: bold;">var</span> back<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">MovieClip</span> = <span style="color: #0033ff; font-weight: bold;">new</span> Back_mc<span style="color: #000066; font-weight: bold;">;</span>
back<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">x</span> = <span style="color: #004993;">stage</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">stageWidth</span> <span style="color: #000066; font-weight: bold;">&amp;</span>gt<span style="color: #000066; font-weight: bold;">;&amp;</span>gt<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>
back<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">y</span> = <span style="color: #000000; font-weight:bold;">40</span><span style="color: #000066; font-weight: bold;">;</span>
back<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">visible</span>=<span style="color: #0033ff; font-weight: bold;">false</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
<span style="color: #004993;">addChild</span><span style="color: #000000;">&#40;</span> back <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
back<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">MouseEvent</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">CLICK</span> <span style="color: #000066; font-weight: bold;">,</span> <span style="color: #339966; font-weight: bold;">function</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#123;</span>
showBack<span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">false</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>
&nbsp;
<span style="color: #000000;">&#40;</span><span style="color: #339966; font-weight: bold;">function</span> <span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
<span style="color: #0033ff; font-weight: bold;">for</span><span style="color: #000000;">&#40;</span><span style="color: #6699cc; font-weight: bold;">var</span> i<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">int</span> = <span style="color: #000000; font-weight:bold;">0</span> <span style="color: #000066; font-weight: bold;">;</span> i <span style="color: #000000; font-weight:bold;">90</span> <span style="color: #000000;">&#41;</span><span style="color: #000000;">&#123;</span>
container<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">visible</span> = <span style="color: #0033ff; font-weight: bold;">false</span><span style="color: #000066; font-weight: bold;">;</span>
back<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">visible</span> = <span style="color: #0033ff; font-weight: bold;">true</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><span style="color: #0033ff; font-weight: bold;">else</span><span style="color: #000000;">&#123;</span>
_update = <span style="color: #339966; font-weight: bold;">function</span> <span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
<span style="color: #0033ff; font-weight: bold;">if</span><span style="color: #000000;">&#40;</span> container<span style="color: #000066; font-weight: bold;">.</span>rotationY <span style="color: #000066; font-weight: bold;">&amp;</span>lt<span style="color: #000066; font-weight: bold;">;</span> <span style="color: #000000; font-weight:bold;">90</span> <span style="color: #000000;">&#41;</span><span style="color: #000000;">&#123;</span>
container<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">visible</span> = <span style="color: #0033ff; font-weight: bold;">true</span><span style="color: #000066; font-weight: bold;">;</span>
back<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">visible</span> = <span style="color: #0033ff; font-weight: bold;">false</span><span style="color: #000066; font-weight: bold;">;</span>
<span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span>
_onComplete = <span style="color: #339966; font-weight: bold;">function</span> <span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</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;">ENTER_FRAME</span> <span style="color: #000066; font-weight: bold;">,</span> enterFrameHandler<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
<span style="color: #000000;">&#125;</span>
&nbsp;
<span style="color: #000000;">&#125;</span>
TweenMax<span style="color: #000066; font-weight: bold;">.</span>to<span style="color: #000000;">&#40;</span> container <span style="color: #000066; font-weight: bold;">,</span> <span style="color: #000066; font-weight: bold;">.</span>7 <span style="color: #000066; font-weight: bold;">,</span> <span style="color: #000000;">&#123;</span>
rotationY<span style="color: #000066; font-weight: bold;">:</span>_targetV<span style="color: #000066; font-weight: bold;">,</span>
onUpdate<span style="color: #000066; font-weight: bold;">:</span>_update<span style="color: #000066; font-weight: bold;">,</span>
onComplete<span style="color: #000066; font-weight: bold;">:</span>_onComplete
<span style="color: #000000;">&#125;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
TweenMax<span style="color: #000066; font-weight: bold;">.</span>to<span style="color: #000000;">&#40;</span> back <span style="color: #000066; font-weight: bold;">,</span> <span style="color: #000066; font-weight: bold;">.</span>7 <span style="color: #000066; font-weight: bold;">,</span> <span style="color: #000000;">&#123;</span> rotationY<span style="color: #000066; font-weight: bold;">:</span>_targetV <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>
&nbsp;
<span style="color: #339966; font-weight: bold;">function</span> enterFrameHandler <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: #6699cc; font-weight: bold;">var</span> _value<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span> = <span style="color: #004993;">stage</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">stageWidth</span><span style="color: #000066; font-weight: bold;">*.</span>5 <span style="color: #000066; font-weight: bold;">-</span> <span style="color: #004993;">mouseX</span><span style="color: #000066; font-weight: bold;">;</span>
_value <span style="color: #000066; font-weight: bold;">*</span>= <span style="color: #000000; font-weight:bold;">0.05</span><span style="color: #000066; font-weight: bold;">;</span>
container<span style="color: #000066; font-weight: bold;">.</span>rotationY <span style="color: #000066; font-weight: bold;">+</span>= <span style="color: #000000;">&#40;</span>_value <span style="color: #000066; font-weight: bold;">-</span> container<span style="color: #000066; font-weight: bold;">.</span>rotationY<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">/</span><span style="color: #000000; font-weight:bold;">10</span><span style="color: #000066; font-weight: bold;">;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p><img src="http://1.bp.blogspot.com/-ArhylaMHRLk/TsSBqDOsAMI/AAAAAAAABA8/YAJG8-cDcm8/s320/2011-11-17_113744.jpg" alt="" /><br />
<a title="SourceCode" href="http://dl.dropbox.com/u/2069696/blog/2011_08_07_3DFlow/2011_08_07_3DFlow.zip">SourceCode</a></p>
<p>Related posts:<ol>
<li><a href='http://blog.richmediaplus.com/2011/05/bitmap-smooth-slow-motion-tip/' rel='bookmark' title='點陣圖慢速平滑移動技巧'>點陣圖慢速平滑移動技巧</a></li>
<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/2009/12/as3-project-custom-preload-load-application/' rel='bookmark' title='AS3工程 Custom Preloader 動態加載 Application'>AS3工程 Custom Preloader 動態加載 Application</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://blog.richmediaplus.com/2011/11/%e7%b0%a1%e6%98%93%e7%89%88-3d-banner-%e6%95%88%e6%9e%9c/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>Away3D4 stage3D Coverflow</title>
		<link>http://blog.richmediaplus.com/2011/11/away3d4-stage3d-coverflow/</link>
		<comments>http://blog.richmediaplus.com/2011/11/away3d4-stage3d-coverflow/#comments</comments>
		<pubDate>Wed, 02 Nov 2011 06:57:19 +0000</pubDate>
		<dc:creator>milkmidi</dc:creator>
				<category><![CDATA[ActionScript3]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[3D]]></category>
		<category><![CDATA[Away3D]]></category>
		<category><![CDATA[Coverflow]]></category>

		<guid isPermaLink="false">http://blog.richmediaplus.com/?p=874</guid>
		<description><![CDATA[大家好，我是奶綠茶 今天來分享一下如何使用 Away3D4 製作經典的 Coverflow 效果 之前都是習慣用 PV3D 製作，但 PV3D 沒有推出 Stage3D 的版本，只好轉戰 Away3D 還好之前有玩過，寫起來長的差不多。 原理和之前分享過的幾篇 Coverflow 教學一樣 同時也練習了一下 Robotlegs , Demo如下。 SourceCodeDownload(DropBox) 在線Demo Source 其中 ScrollBar 類別是使用 clockmaker 這篇的教學 http://clockmaker.jp/blog/2011/10/stage3d-cover-flow/ Related posts: StarlingFramework hitTestTarget(source:DisplayObject, target:DisplayObject):Boolean 2009 Adobe Flash / Adobe Flex 重點留意關鍵字
Related posts:<ol>
<li><a href='http://blog.richmediaplus.com/2011/10/starlingframework/' rel='bookmark' title='StarlingFramework'>StarlingFramework</a></li>
<li><a href='http://blog.richmediaplus.com/2010/04/hit-test-target-hit-test-object/' rel='bookmark' title='hitTestTarget(source:DisplayObject, target:DisplayObject):Boolean'>hitTestTarget(source:DisplayObject, target:DisplayObject):Boolean</a></li>
<li><a href='http://blog.richmediaplus.com/2009/06/keywords-about-the-adobe-flex-flash-in-2009/' rel='bookmark' title='2009 Adobe Flash / Adobe Flex 重點留意關鍵字'>2009 Adobe Flash / Adobe Flex 重點留意關鍵字</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>大家好，我是奶綠茶<br />
今天來分享一下如何使用 Away3D4 製作經典的 Coverflow 效果<br />
之前都是習慣用 PV3D 製作，但 PV3D 沒有推出 Stage3D 的版本，只好轉戰 Away3D<br />
還好之前有玩過，寫起來長的差不多。<br />
原理和之前分享過的幾篇 Coverflow 教學一樣<br />
同時也練習了一下 Robotlegs , Demo如下。<br />
<a target="_blank" href="http://dl.dropbox.com/u/2069696/blog/2011_11_02_away3d4_coverflow/index.html"><br />
<img src="http://dl.dropbox.com/u/2069696/blog/2011_11_02_away3d4_coverflow/snapshot.jpg" alt="away3d" /></a><br />
<a href="http://dl.dropbox.com/u/2069696/blog/2011_11_02_away3d4_coverflow/source.zip">SourceCodeDownload(DropBox)</a><br />
<a href="http://code.richmediaplus.com/milkmidi/coverflow3D/" title="coverflow3D Demo" target="_blank">在線Demo</a><br />
<a href="http://code.richmediaplus.com/milkmidi/coverflow3D/source.zip" title="coverflow3D Source" target="_blank">Source</a><br />
其中 ScrollBar 類別是使用 clockmaker 這篇的教學<br />
<a href="http://clockmaker.jp/blog/2011/10/stage3d-cover-flow/" target="_blank">http://clockmaker.jp/blog/2011/10/stage3d-cover-flow/</a></p>
<p>Related posts:<ol>
<li><a href='http://blog.richmediaplus.com/2011/10/starlingframework/' rel='bookmark' title='StarlingFramework'>StarlingFramework</a></li>
<li><a href='http://blog.richmediaplus.com/2010/04/hit-test-target-hit-test-object/' rel='bookmark' title='hitTestTarget(source:DisplayObject, target:DisplayObject):Boolean'>hitTestTarget(source:DisplayObject, target:DisplayObject):Boolean</a></li>
<li><a href='http://blog.richmediaplus.com/2009/06/keywords-about-the-adobe-flex-flash-in-2009/' rel='bookmark' title='2009 Adobe Flash / Adobe Flex 重點留意關鍵字'>2009 Adobe Flash / Adobe Flex 重點留意關鍵字</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://blog.richmediaplus.com/2011/11/away3d4-stage3d-coverflow/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>
	</channel>
</rss>

