<?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; Adobe Flex</title>
	<atom:link href="http://blog.richmediaplus.com/tag/adobe-flex/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 滑鼠游標實體</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>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>Spark 多重欄位排序的 DataGrid</title>
		<link>http://blog.richmediaplus.com/2011/09/spark-multi-column-sortable-datagrid/</link>
		<comments>http://blog.richmediaplus.com/2011/09/spark-multi-column-sortable-datagrid/#comments</comments>
		<pubDate>Thu, 15 Sep 2011 06:58:51 +0000</pubDate>
		<dc:creator>Ticore Shih</dc:creator>
				<category><![CDATA[ActionScript3]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[Adobe Flex]]></category>

		<guid isPermaLink="false">http://blog.richmediaplus.com/?p=818</guid>
		<description><![CDATA[Flex 4.5 Spark 雖然提供了 DataGrid 可是它沒有像 mx:AdvancedDataGrid 那樣支援多 Column 排序功能 看到 Adobe Cookbooks &#8211; How do I perform a multicolumn sort in a Spark DataGrid? 有人提供，可是那幾乎是寫死在組件外部 不能讓 User 自己選擇排序欄位 所以我想辦法繼承 Spark DataGrid，複寫 columnHeaderGroup_clickHandler 函式 當 User 在 Column Header 同時按下 Ctrl + Mouse Left Click 時 提供多重 Column 排序的功能 MultiColSortableDataGrid.as package &#123; import mx.collections.ICollectionView; import [...]
Related posts:<ol>
<li><a href='http://blog.richmediaplus.com/2011/08/spark-richeditabletext-maxchars-issue/' rel='bookmark' title='Flex 4.5 Spark RichEditableText maxChars 與輸入法問題'>Flex 4.5 Spark RichEditableText maxChars 與輸入法問題</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/2009/04/create-trail-information-and-expired-date-in-actionscript3-and-flex3/' rel='bookmark' title='Create Trail Information &amp; Expired Date in ActionScript3 &amp; Flex'>Create Trail Information &#038; Expired Date in ActionScript3 &#038; Flex</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>Flex 4.5 Spark 雖然提供了 DataGrid<br />
可是它沒有像 mx:AdvancedDataGrid 那樣支援多 Column 排序功能<br />
看到 <a href="http://cookbooks.adobe.com/post_How_do_I_perform_a_multicolumn_support_in_a_Spark-19300.html">Adobe Cookbooks &#8211; How do I perform a multicolumn sort in a Spark DataGrid?</a><br />
有人提供，可是那幾乎是寫死在組件外部<br />
不能讓 User 自己選擇排序欄位<br />
所以我想辦法繼承 Spark DataGrid，複寫 columnHeaderGroup_clickHandler 函式<br />
當 User 在 Column Header 同時按下 Ctrl + Mouse Left Click 時<br />
提供多重 Column 排序的功能</p>
<p>MultiColSortableDataGrid.as</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #9900cc; font-weight: bold;">package</span> <span style="color: #000000;">&#123;</span>
	<span style="color: #0033ff; font-weight: bold;">import</span> mx<span style="color: #000066; font-weight: bold;">.</span>collections<span style="color: #000066; font-weight: bold;">.</span>ICollectionView<span style="color: #000066; font-weight: bold;">;</span>
	<span style="color: #0033ff; font-weight: bold;">import</span> mx<span style="color: #000066; font-weight: bold;">.</span>collections<span style="color: #000066; font-weight: bold;">.</span>IList<span style="color: #000066; font-weight: bold;">;</span>
	<span style="color: #0033ff; font-weight: bold;">import</span> mx<span style="color: #000066; font-weight: bold;">.</span>collections<span style="color: #000066; font-weight: bold;">.</span>ISort<span style="color: #000066; font-weight: bold;">;</span>
	<span style="color: #0033ff; font-weight: bold;">import</span> mx<span style="color: #000066; font-weight: bold;">.</span>collections<span style="color: #000066; font-weight: bold;">.</span>ISortField<span style="color: #000066; font-weight: bold;">;</span>
	<span style="color: #0033ff; font-weight: bold;">import</span> mx<span style="color: #000066; font-weight: bold;">.</span>collections<span style="color: #000066; font-weight: bold;">.</span>Sort<span style="color: #000066; font-weight: bold;">;</span>
	<span style="color: #0033ff; font-weight: bold;">import</span> mx<span style="color: #000066; font-weight: bold;">.</span>styles<span style="color: #000066; font-weight: bold;">.</span>AdvancedStyleClient<span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
	<span style="color: #0033ff; font-weight: bold;">import</span> spark<span style="color: #000066; font-weight: bold;">.</span>components<span style="color: #000066; font-weight: bold;">.</span>DataGrid<span style="color: #000066; font-weight: bold;">;</span>
	<span style="color: #0033ff; font-weight: bold;">import</span> spark<span style="color: #000066; font-weight: bold;">.</span>components<span style="color: #000066; font-weight: bold;">.</span>Grid<span style="color: #000066; font-weight: bold;">;</span>
	<span style="color: #0033ff; font-weight: bold;">import</span> spark<span style="color: #000066; font-weight: bold;">.</span>components<span style="color: #000066; font-weight: bold;">.</span>gridClasses<span style="color: #000066; font-weight: bold;">.</span>GridColumn<span style="color: #000066; font-weight: bold;">;</span>
	<span style="color: #0033ff; font-weight: bold;">import</span> spark<span style="color: #000066; font-weight: bold;">.</span>components<span style="color: #000066; font-weight: bold;">.</span>gridClasses<span style="color: #000066; font-weight: bold;">.</span>GridSortField<span style="color: #000066; font-weight: bold;">;</span>
	<span style="color: #0033ff; font-weight: bold;">import</span> spark<span style="color: #000066; font-weight: bold;">.</span>events<span style="color: #000066; font-weight: bold;">.</span>GridEvent<span style="color: #000066; font-weight: bold;">;</span>
	<span style="color: #0033ff; font-weight: bold;">import</span> spark<span style="color: #000066; font-weight: bold;">.</span>events<span style="color: #000066; font-weight: bold;">.</span>GridSortEvent<span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
	<span style="color: #3f5fbf;">/**
	 *  Multi-column sortable data grid class.
	 *  Extends spark data grid and override columnHeaderGroup_clickHandler function.
	 *  Provide multi-column sort function when ctrl + left click on column header.
	 */</span>
	<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #9900cc; font-weight: bold;">class</span> MultiColSortableDataGrid <span style="color: #0033ff; font-weight: bold;">extends</span> DataGrid <span style="color: #000000;">&#123;</span>
&nbsp;
		<span style="color: #3f5fbf;">/**
		 *  @private
		 */</span>
		override <span style="color: #0033ff; font-weight: bold;">protected</span> <span style="color: #339966; font-weight: bold;">function</span> columnHeaderGroup_clickHandler<span style="color: #000000;">&#40;</span>event<span style="color: #000066; font-weight: bold;">:</span>GridEvent<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>
			const column<span style="color: #000066; font-weight: bold;">:</span>GridColumn = event<span style="color: #000066; font-weight: bold;">.</span>column<span style="color: #000066; font-weight: bold;">;</span>
			<span style="color: #6699cc; font-weight: bold;">var</span> columnIndices<span style="color: #000066; font-weight: bold;">:</span>Vector<span style="color: #000066; font-weight: bold;">.&lt;</span>int<span style="color: #000066; font-weight: bold;">&gt;;</span>
&nbsp;
			<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #000066; font-weight: bold;">!</span><span style="color: #004993;">enabled</span> <span style="color: #000066; font-weight: bold;">||</span> <span style="color: #000066; font-weight: bold;">!</span>sortableColumns <span style="color: #000066; font-weight: bold;">||</span> <span style="color: #000066; font-weight: bold;">!</span>column <span style="color: #000066; font-weight: bold;">||</span> <span style="color: #000066; font-weight: bold;">!</span>column<span style="color: #000066; font-weight: bold;">.</span>sortable<span style="color: #000000;">&#41;</span>
				<span style="color: #0033ff; font-weight: bold;">return</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
			columnIndices = Vector<span style="color: #000066; font-weight: bold;">.&lt;</span>int<span style="color: #000066; font-weight: bold;">&gt;</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#91;</span>column<span style="color: #000066; font-weight: bold;">.</span>columnIndex<span style="color: #000000;">&#93;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
			<span style="color: #009900; font-style: italic;">// If the sort isn't cancelled, will also update the columnHeaderGroup</span>
			<span style="color: #009900; font-style: italic;">// visibleSortIndiciatorIndices.</span>
&nbsp;
			sortByMultiColumns<span style="color: #000000;">&#40;</span>columnIndices<span style="color: #000066; font-weight: bold;">,</span> <span style="color: #0033ff; font-weight: bold;">true</span><span style="color: #000066; font-weight: bold;">,</span> event<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">ctrlKey</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
		<span style="color: #000000;">&#125;</span>
&nbsp;
&nbsp;
&nbsp;
	    <span style="color: #3f5fbf;">/**
		 *  Copy and modify from DataGrid::sortByColumns function.
	     *  Add one more argument multiColSort, decide if continue to use old sort fields.
		 *  Achieve multi-column sort function.
	     */</span>
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> sortByMultiColumns<span style="color: #000000;">&#40;</span>columnIndices<span style="color: #000066; font-weight: bold;">:</span>Vector<span style="color: #000066; font-weight: bold;">.&lt;</span>int<span style="color: #000066; font-weight: bold;">&gt;,</span>
							isInteractive<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Boolean</span> = <span style="color: #0033ff; font-weight: bold;">false</span> <span style="color: #000066; font-weight: bold;">,</span> multiColSort<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Boolean</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: #004993;">Boolean</span> <span style="color: #000000;">&#123;</span>
&nbsp;
			const dataProvider<span style="color: #000066; font-weight: bold;">:</span>ICollectionView = <span style="color: #0033ff; font-weight: bold;">this</span><span style="color: #000066; font-weight: bold;">.</span>dataProvider <span style="color: #0033ff; font-weight: bold;">as</span> ICollectionView<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>dataProvider<span style="color: #000000;">&#41;</span>
				<span style="color: #0033ff; font-weight: bold;">return</span> <span style="color: #0033ff; font-weight: bold;">false</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
			<span style="color: #6699cc; font-weight: bold;">var</span> <span style="color: #004993;">sort</span><span style="color: #000066; font-weight: bold;">:</span>ISort = dataProvider<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">sort</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: #004993;">sort</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
				<span style="color: #004993;">sort</span><span style="color: #000066; font-weight: bold;">.</span>compareFunction = <span style="color: #0033ff; font-weight: bold;">null</span><span style="color: #000066; font-weight: bold;">;</span>
			<span style="color: #000000;">&#125;</span> <span style="color: #0033ff; font-weight: bold;">else</span> <span style="color: #000000;">&#123;</span>
				<span style="color: #004993;">sort</span> = <span style="color: #0033ff; font-weight: bold;">new</span> Sort<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
			<span style="color: #000000;">&#125;</span>
			<span style="color: #6699cc; font-weight: bold;">var</span> sortFields<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Array</span> = createSortFields<span style="color: #000000;">&#40;</span>columnIndices<span style="color: #000066; font-weight: bold;">,</span> <span style="color: #004993;">sort</span><span style="color: #000066; font-weight: bold;">.</span>fields<span style="color: #000066; font-weight: bold;">,</span> isInteractive<span style="color: #000000;">&#41;</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>sortFields<span style="color: #000000;">&#41;</span>
				<span style="color: #0033ff; font-weight: bold;">return</span> <span style="color: #0033ff; font-weight: bold;">false</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
			<span style="color: #6699cc; font-weight: bold;">var</span> oldSortFields<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Array</span> = <span style="color: #000000;">&#40;</span>dataProvider<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">sort</span><span style="color: #000000;">&#41;</span> <span style="color: #000066; font-weight: bold;">?</span> dataProvider<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">sort</span><span style="color: #000066; font-weight: bold;">.</span>fields <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #0033ff; font-weight: bold;">null</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
&nbsp;
			<span style="color: #009900; font-style: italic;">// implements multi-column sort function.</span>
			<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>multiColSort <span style="color: #000066; font-weight: bold;">&amp;&amp;</span> oldSortFields<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>columnHeaderGroup<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
					<span style="color: #6699cc; font-weight: bold;">var</span> colSortIndices<span style="color: #000066; font-weight: bold;">:</span>Vector<span style="color: #000066; font-weight: bold;">.&lt;</span>int<span style="color: #000066; font-weight: bold;">&gt;</span> = columnHeaderGroup<span style="color: #000066; font-weight: bold;">.</span>visibleSortIndicatorIndices<span style="color: #000066; font-weight: bold;">;</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> j<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">int</span> = colSortIndices<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">length</span> <span style="color: #000066; font-weight: bold;">-</span> <span style="color: #000000; font-weight:bold;">1</span> <span style="color: #000066; font-weight: bold;">;</span> j <span style="color: #000066; font-weight: bold;">&gt;</span>= <span style="color: #000000; font-weight:bold;">0</span> <span style="color: #000066; font-weight: bold;">;</span> <span style="color: #000066; font-weight: bold;">--</span>j<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
						<span style="color: #6699cc; font-weight: bold;">var</span> idx<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">int</span> = colSortIndices<span style="color: #000000;">&#91;</span>j<span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">;</span>
						<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>columnIndices<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">indexOf</span><span style="color: #000000;">&#40;</span>idx<span style="color: #000000;">&#41;</span> <span style="color: #000066; font-weight: bold;">&lt;</span> <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
							columnIndices<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">unshift</span><span style="color: #000000;">&#40;</span>idx<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>
&nbsp;
				outer<span style="color: #000066; font-weight: bold;">:</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> = oldSortFields<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">length</span> <span style="color: #000066; font-weight: bold;">-</span> <span style="color: #000000; font-weight:bold;">1</span> <span style="color: #000066; font-weight: bold;">;</span> i <span style="color: #000066; font-weight: bold;">&gt;</span>= <span style="color: #000000; font-weight:bold;">0</span> <span style="color: #000066; font-weight: bold;">;</span> <span style="color: #000066; font-weight: bold;">--</span>i<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
					<span style="color: #6699cc; font-weight: bold;">var</span> oldField<span style="color: #000066; font-weight: bold;">:</span>ISortField = oldSortFields<span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span> <span style="color: #0033ff; font-weight: bold;">as</span> ISortField<span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
					<span style="color: #0033ff; font-weight: bold;">for</span> <span style="color: #000000;">&#40;</span><span style="color: #6699cc; font-weight: bold;">var</span> k<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> k <span style="color: #000066; font-weight: bold;">&lt;</span> sortFields<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">length</span> <span style="color: #000066; font-weight: bold;">;</span> <span style="color: #000066; font-weight: bold;">++</span>k<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
						<span style="color: #6699cc; font-weight: bold;">var</span> newField<span style="color: #000066; font-weight: bold;">:</span>ISortField = sortFields<span style="color: #000000;">&#91;</span>k<span style="color: #000000;">&#93;</span> <span style="color: #0033ff; font-weight: bold;">as</span> ISortField<span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
						<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>newField<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">name</span> == oldField<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">name</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
							<span style="color: #0033ff; font-weight: bold;">continue</span> outer<span style="color: #000066; font-weight: bold;">;</span>
						<span style="color: #000000;">&#125;</span>
					<span style="color: #000000;">&#125;</span>
					sortFields<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">unshift</span><span style="color: #000000;">&#40;</span>oldField<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>
&nbsp;
&nbsp;
			<span style="color: #009900; font-style: italic;">// Dispatch the &quot;changing&quot; event. If preventDefault() is called</span>
			<span style="color: #009900; font-style: italic;">// on this event, the sort operation will be cancelled.  If columnIndices or</span>
			<span style="color: #009900; font-style: italic;">// sortFields are changed, the new values will be used.</span>
			<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>isInteractive<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
				<span style="color: #009900; font-style: italic;">// This is a shallow copy which means only the pointers to the ISortField objects</span>
				<span style="color: #009900; font-style: italic;">// are copied to the new Array, not the ISortField objects themselves.</span>
				<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>oldSortFields<span style="color: #000000;">&#41;</span>
					oldSortFields = oldSortFields<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">concat</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
				<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #004993;">hasEventListener</span><span style="color: #000000;">&#40;</span>GridSortEvent<span style="color: #000066; font-weight: bold;">.</span>SORT_CHANGING<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
					const changingEvent<span style="color: #000066; font-weight: bold;">:</span>GridSortEvent =
						<span style="color: #0033ff; font-weight: bold;">new</span> GridSortEvent<span style="color: #000000;">&#40;</span>GridSortEvent<span style="color: #000066; font-weight: bold;">.</span>SORT_CHANGING<span style="color: #000066; font-weight: bold;">,</span>
						<span style="color: #0033ff; font-weight: bold;">false</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #0033ff; font-weight: bold;">true</span><span style="color: #000066; font-weight: bold;">,</span>
						columnIndices<span style="color: #000066; font-weight: bold;">,</span>
						oldSortFields<span style="color: #000066; font-weight: bold;">,</span> <span style="color: #009966; font-style: italic;">/* intended to be read-only but no way to enforce this */</span>
						sortFields<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
					<span style="color: #009900; font-style: italic;">// The event was cancelled so don't sort.</span>
					<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #000066; font-weight: bold;">!</span><span style="color: #004993;">dispatchEvent</span><span style="color: #000000;">&#40;</span>changingEvent<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>
						<span style="color: #0033ff; font-weight: bold;">return</span> <span style="color: #0033ff; font-weight: bold;">false</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
					<span style="color: #009900; font-style: italic;">// Update the sort columns since they might have changed.</span>
					columnIndices = changingEvent<span style="color: #000066; font-weight: bold;">.</span>columnIndices<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>columnIndices<span style="color: #000000;">&#41;</span>
						<span style="color: #0033ff; font-weight: bold;">return</span> <span style="color: #0033ff; font-weight: bold;">false</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
					<span style="color: #009900; font-style: italic;">// Update the new sort fields since they might have changed.</span>
					sortFields = changingEvent<span style="color: #000066; font-weight: bold;">.</span>newSortFields<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>sortFields<span style="color: #000000;">&#41;</span>
						<span style="color: #0033ff; font-weight: bold;">return</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>
&nbsp;
			<span style="color: #009900; font-style: italic;">// Remove each old SortField that's not a member of the new sortFields Array</span>
			<span style="color: #009900; font-style: italic;">// as a &quot;styleClient&quot; of this DataGrid.</span>
&nbsp;
			<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>oldSortFields<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
				<span style="color: #0033ff; font-weight: bold;">for</span> <span style="color: #0033ff; font-weight: bold;">each</span> <span style="color: #000000;">&#40;</span><span style="color: #6699cc; font-weight: bold;">var</span> oldSortField<span style="color: #000066; font-weight: bold;">:</span>ISortField <span style="color: #0033ff; font-weight: bold;">in</span> oldSortFields<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
					<span style="color: #6699cc; font-weight: bold;">var</span> oldASC<span style="color: #000066; font-weight: bold;">:</span>AdvancedStyleClient = oldSortField <span style="color: #0033ff; font-weight: bold;">as</span> AdvancedStyleClient<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>oldASC <span style="color: #000066; font-weight: bold;">||</span> <span style="color: #000000;">&#40;</span>oldASC<span style="color: #000066; font-weight: bold;">.</span>styleParent <span style="color: #000066; font-weight: bold;">!</span>= <span style="color: #0033ff; font-weight: bold;">this</span><span style="color: #000000;">&#41;</span> <span style="color: #000066; font-weight: bold;">||</span> <span style="color: #000000;">&#40;</span>sortFields<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">indexOf</span><span style="color: #000000;">&#40;</span>oldASC<span style="color: #000000;">&#41;</span> <span style="color: #000066; font-weight: bold;">!</span>= <span style="color: #000066; font-weight: bold;">-</span><span style="color: #000000; font-weight:bold;">1</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>
						<span style="color: #0033ff; font-weight: bold;">continue</span><span style="color: #000066; font-weight: bold;">;</span>
					removeStyleClient<span style="color: #000000;">&#40;</span>oldASC<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>
&nbsp;
			<span style="color: #009900; font-style: italic;">// Add new SortFields as &quot;styleClients&quot; of this DataGrid so that they</span>
			<span style="color: #009900; font-style: italic;">// inherit this DataGrid's locale style. </span>
&nbsp;
			<span style="color: #0033ff; font-weight: bold;">for</span> <span style="color: #0033ff; font-weight: bold;">each</span> <span style="color: #000000;">&#40;</span><span style="color: #6699cc; font-weight: bold;">var</span> newSortField<span style="color: #000066; font-weight: bold;">:</span>ISortField <span style="color: #0033ff; font-weight: bold;">in</span> sortFields<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
				<span style="color: #6699cc; font-weight: bold;">var</span> newASC<span style="color: #000066; font-weight: bold;">:</span>AdvancedStyleClient = newSortField <span style="color: #0033ff; font-weight: bold;">as</span> AdvancedStyleClient<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>newASC <span style="color: #000066; font-weight: bold;">||</span> <span style="color: #000000;">&#40;</span>newASC<span style="color: #000066; font-weight: bold;">.</span>styleParent == <span style="color: #0033ff; font-weight: bold;">this</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>
					<span style="color: #0033ff; font-weight: bold;">continue</span><span style="color: #000066; font-weight: bold;">;</span>
				addStyleClient<span style="color: #000000;">&#40;</span>newASC<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
			<span style="color: #000000;">&#125;</span>
&nbsp;
			<span style="color: #004993;">sort</span><span style="color: #000066; font-weight: bold;">.</span>fields = sortFields<span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
			dataProvider<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">sort</span> = <span style="color: #004993;">sort</span><span style="color: #000066; font-weight: bold;">;</span>
			dataProvider<span style="color: #000066; font-weight: bold;">.</span>refresh<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
			<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>isInteractive<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
				<span style="color: #009900; font-style: italic;">// Dispatch the &quot;change&quot; event.</span>
				<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #004993;">hasEventListener</span><span style="color: #000000;">&#40;</span>GridSortEvent<span style="color: #000066; font-weight: bold;">.</span>SORT_CHANGE<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
					const changeEvent<span style="color: #000066; font-weight: bold;">:</span>GridSortEvent =
						<span style="color: #0033ff; font-weight: bold;">new</span> GridSortEvent<span style="color: #000000;">&#40;</span>GridSortEvent<span style="color: #000066; font-weight: bold;">.</span>SORT_CHANGE<span style="color: #000066; font-weight: bold;">,</span>
						<span style="color: #0033ff; font-weight: bold;">false</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #0033ff; font-weight: bold;">true</span><span style="color: #000066; font-weight: bold;">,</span>
						columnIndices<span style="color: #000066; font-weight: bold;">,</span>
						oldSortFields<span style="color: #000066; font-weight: bold;">,</span> sortFields<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
					<span style="color: #004993;">dispatchEvent</span><span style="color: #000000;">&#40;</span>changeEvent<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
				<span style="color: #000000;">&#125;</span>
&nbsp;
				<span style="color: #009900; font-style: italic;">// Update the visible sort indicators.</span>
				<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>columnHeaderGroup<span style="color: #000000;">&#41;</span>
					columnHeaderGroup<span style="color: #000066; font-weight: bold;">.</span>visibleSortIndicatorIndices = columnIndices<span style="color: #000066; font-weight: bold;">;</span>
			<span style="color: #000000;">&#125;</span>
&nbsp;
			<span style="color: #0033ff; font-weight: bold;">return</span> <span style="color: #0033ff; font-weight: bold;">true</span><span style="color: #000066; font-weight: bold;">;</span>
		<span style="color: #000000;">&#125;</span>
&nbsp;
&nbsp;
	    <span style="color: #3f5fbf;">/**
	     *  @private
	     *  Copy from DataGrid::createSortFields function.
	     */</span>
		<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> createSortFields<span style="color: #000000;">&#40;</span>columnIndices<span style="color: #000066; font-weight: bold;">:</span>Vector<span style="color: #000066; font-weight: bold;">.&lt;</span>int<span style="color: #000066; font-weight: bold;">&gt;,</span>
									previousFields<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Array</span><span style="color: #000066; font-weight: bold;">,</span> preservePrevious<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Boolean</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>
			<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>columnIndices<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">length</span> == <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000000;">&#41;</span>
				<span style="color: #0033ff; font-weight: bold;">return</span> <span style="color: #0033ff; font-weight: bold;">null</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
			<span style="color: #6699cc; font-weight: bold;">var</span> fields<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Array</span> = <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">Array</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
			<span style="color: #0033ff; font-weight: bold;">for</span> <span style="color: #0033ff; font-weight: bold;">each</span> <span style="color: #000000;">&#40;</span><span style="color: #6699cc; font-weight: bold;">var</span> columnIndex<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">int</span> <span style="color: #0033ff; font-weight: bold;">in</span> columnIndices<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
				<span style="color: #6699cc; font-weight: bold;">var</span> col<span style="color: #000066; font-weight: bold;">:</span>GridColumn = <span style="color: #0033ff; font-weight: bold;">this</span><span style="color: #000066; font-weight: bold;">.</span>getColumnAt<span style="color: #000000;">&#40;</span>columnIndex<span style="color: #000000;">&#41;</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>col<span style="color: #000000;">&#41;</span>
					<span style="color: #0033ff; font-weight: bold;">return</span> <span style="color: #0033ff; font-weight: bold;">null</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
				<span style="color: #6699cc; font-weight: bold;">var</span> dataField<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">String</span> = col<span style="color: #000066; font-weight: bold;">.</span>dataField<span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
				<span style="color: #009900; font-style: italic;">// columns all must have a dataField or a labelFunction or a sortCompareFunction</span>
				<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>dataField == <span style="color: #0033ff; font-weight: bold;">null</span> <span style="color: #000066; font-weight: bold;">&amp;&amp;</span> col<span style="color: #000066; font-weight: bold;">.</span>labelFunction == <span style="color: #0033ff; font-weight: bold;">null</span> <span style="color: #000066; font-weight: bold;">&amp;&amp;</span> col<span style="color: #000066; font-weight: bold;">.</span>sortCompareFunction == <span style="color: #0033ff; font-weight: bold;">null</span><span style="color: #000000;">&#41;</span>
					<span style="color: #0033ff; font-weight: bold;">return</span> <span style="color: #0033ff; font-weight: bold;">null</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
				const isComplexDataField<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Boolean</span> = <span style="color: #000000;">&#40;</span>dataField <span style="color: #000066; font-weight: bold;">&amp;&amp;</span> <span style="color: #000000;">&#40;</span>dataField<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">indexOf</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;.&quot;</span><span style="color: #000000;">&#41;</span> <span style="color: #000066; font-weight: bold;">!</span>= <span style="color: #000066; font-weight: bold;">-</span><span style="color: #000000; font-weight:bold;">1</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
				<span style="color: #6699cc; font-weight: bold;">var</span> sortField<span style="color: #000066; font-weight: bold;">:</span>ISortField = <span style="color: #0033ff; font-weight: bold;">null</span><span style="color: #000066; font-weight: bold;">;</span>
				<span style="color: #6699cc; font-weight: bold;">var</span> sortDescending<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Boolean</span> = col<span style="color: #000066; font-weight: bold;">.</span>sortDescending<span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
				<span style="color: #009900; font-style: italic;">// Check if we just sorted this column.</span>
				sortField = findSortField<span style="color: #000000;">&#40;</span>dataField<span style="color: #000066; font-weight: bold;">,</span> fields<span style="color: #000066; font-weight: bold;">,</span> isComplexDataField<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
				<span style="color: #009900; font-style: italic;">// If we haven't sorted by this column yet, check if</span>
				<span style="color: #009900; font-style: italic;">// we've sorted by this column in the previous sort.</span>
				<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #000066; font-weight: bold;">!</span>sortField <span style="color: #000066; font-weight: bold;">&amp;&amp;</span> previousFields<span style="color: #000000;">&#41;</span>
					sortField = findSortField<span style="color: #000000;">&#40;</span>dataField<span style="color: #000066; font-weight: bold;">,</span> previousFields<span style="color: #000066; font-weight: bold;">,</span> isComplexDataField<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
				<span style="color: #0033ff; font-weight: bold;">else</span>
					preservePrevious = <span style="color: #0033ff; font-weight: bold;">false</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
				<span style="color: #009900; font-style: italic;">// Previously sorted column, so flip sortDescending.</span>
				<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>sortField<span style="color: #000000;">&#41;</span>
					sortDescending = <span style="color: #000066; font-weight: bold;">!</span>sortField<span style="color: #000066; font-weight: bold;">.</span>descending<span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
				<span style="color: #009900; font-style: italic;">// Create a SortField from the column.  If the sortField was found in the</span>
				<span style="color: #009900; font-style: italic;">// previousFields and we need to preserve them, create a new sort field for the column.</span>
				<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #000066; font-weight: bold;">!</span>sortField <span style="color: #000066; font-weight: bold;">||</span> preservePrevious<span style="color: #000000;">&#41;</span>
					sortField = col<span style="color: #000066; font-weight: bold;">.</span>sortField<span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
				col<span style="color: #000066; font-weight: bold;">.</span>sortDescending = sortDescending<span style="color: #000066; font-weight: bold;">;</span>
				sortField<span style="color: #000066; font-weight: bold;">.</span>descending = sortDescending<span style="color: #000066; font-weight: bold;">;</span>
				fields<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">push</span><span style="color: #000000;">&#40;</span>sortField<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
			<span style="color: #000000;">&#125;</span>
&nbsp;
			<span style="color: #0033ff; font-weight: bold;">return</span> fields<span style="color: #000066; font-weight: bold;">;</span>
		<span style="color: #000000;">&#125;</span>
&nbsp;
&nbsp;
	    <span style="color: #3f5fbf;">/**
	     *  @private
	     *  Copy from DataGrid::getColumnAt function.
	     */</span>
		<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> getColumnAt<span style="color: #000000;">&#40;</span>columnIndex<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">int</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span>GridColumn <span style="color: #000000;">&#123;</span>
			const grid<span style="color: #000066; font-weight: bold;">:</span>Grid = grid<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>grid <span style="color: #000066; font-weight: bold;">||</span> <span style="color: #000066; font-weight: bold;">!</span>grid<span style="color: #000066; font-weight: bold;">.</span>columns<span style="color: #000000;">&#41;</span>
				<span style="color: #0033ff; font-weight: bold;">return</span> <span style="color: #0033ff; font-weight: bold;">null</span><span style="color: #000066; font-weight: bold;">;</span>
			const columns<span style="color: #000066; font-weight: bold;">:</span>IList = grid<span style="color: #000066; font-weight: bold;">.</span>columns<span style="color: #000066; font-weight: bold;">;</span>
			<span style="color: #0033ff; font-weight: bold;">return</span> <span style="color: #000000;">&#40;</span><span style="color: #000000;">&#40;</span>columnIndex <span style="color: #000066; font-weight: bold;">&gt;</span>= <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000000;">&#41;</span> <span style="color: #000066; font-weight: bold;">&amp;&amp;</span> <span style="color: #000000;">&#40;</span>columnIndex <span style="color: #000066; font-weight: bold;">&lt;</span> columns<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">length</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span> <span style="color: #000066; font-weight: bold;">?</span>
											columns<span style="color: #000066; font-weight: bold;">.</span>getItemAt<span style="color: #000000;">&#40;</span>columnIndex<span style="color: #000000;">&#41;</span> <span style="color: #0033ff; font-weight: bold;">as</span> GridColumn <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #0033ff; font-weight: bold;">null</span><span style="color: #000066; font-weight: bold;">;</span>
		<span style="color: #000000;">&#125;</span>
&nbsp;
&nbsp;
		<span style="color: #3f5fbf;">/**
		 *  @private
		 *  Copy from DataGrid::findSortField function.
		 * 
		 *  Finds a SortField using the provided dataField and returns it.
		 *  If the dataField is complex, it tries to find a GridSortField
		 *  with a matching dataFieldPath.
		 *
		 *  @param dataField The dataField of the column.
		 *  @param fields The array of SortFields to search through.
		 *  @param isComplexDataField true if the dataField is a path.
		 */</span>
		<span style="color: #0033ff; font-weight: bold;">private</span> static <span style="color: #339966; font-weight: bold;">function</span> findSortField<span style="color: #000000;">&#40;</span>dataField<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">String</span><span style="color: #000066; font-weight: bold;">,</span> fields<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Array</span><span style="color: #000066; font-weight: bold;">,</span> isComplexDataField<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Boolean</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span>ISortField <span style="color: #000000;">&#123;</span>
			<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>dataField == <span style="color: #0033ff; font-weight: bold;">null</span><span style="color: #000000;">&#41;</span>
				<span style="color: #0033ff; font-weight: bold;">return</span> <span style="color: #0033ff; font-weight: bold;">null</span><span style="color: #000066; font-weight: bold;">;</span>
			<span style="color: #0033ff; font-weight: bold;">for</span> <span style="color: #0033ff; font-weight: bold;">each</span> <span style="color: #000000;">&#40;</span><span style="color: #6699cc; font-weight: bold;">var</span> field<span style="color: #000066; font-weight: bold;">:</span>ISortField <span style="color: #0033ff; font-weight: bold;">in</span> fields<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
				<span style="color: #6699cc; font-weight: bold;">var</span> <span style="color: #004993;">name</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">String</span> = field<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">name</span><span style="color: #000066; font-weight: bold;">;</span>
				<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>isComplexDataField <span style="color: #000066; font-weight: bold;">&amp;&amp;</span> <span style="color: #000000;">&#40;</span>field <span style="color: #0033ff; font-weight: bold;">is</span> GridSortField<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
					<span style="color: #004993;">name</span> = GridSortField<span style="color: #000000;">&#40;</span>field<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">.</span>dataFieldPath<span style="color: #000066; font-weight: bold;">;</span>
				<span style="color: #000000;">&#125;</span>
				<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #004993;">name</span> == dataField<span style="color: #000000;">&#41;</span>
					<span style="color: #0033ff; font-weight: bold;">return</span> field<span style="color: #000066; font-weight: bold;">;</span>
			<span style="color: #000000;">&#125;</span>
			<span style="color: #0033ff; font-weight: bold;">return</span> <span style="color: #0033ff; font-weight: bold;">null</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>以上組件就能提供多重欄位排序功能<br />
假如還想要顯示排序優先順序號碼<br />
就需要再提供自訂的 Skin<br />
<a href="https://sites.google.com/site/riafiles/SparkMultiColSortableDataGrid.fxp?attredirects=0&#038;d=1">參考原始檔案</a></p>
<p>Spark 多重欄位排序線上範例：</p>
<p>
<object width="500" height="400">
<param name="movie" value="http://blog-uploads.richmediaplus.com/2011/09/SparkMultiColSortableDataGrid.swf"></param>
<param name="quality" value="high"></param>
<param name="wmode" value="window"></param>
<param name="menu" value="false"></param>
<param name="bgcolor" value="#FFFFFF"></param>
<param name="allowScriptAccess" value="always"></param>
<embed type="application/x-shockwave-flash" width="500" height="400" src="http://blog-uploads.richmediaplus.com/2011/09/SparkMultiColSortableDataGrid.swf" quality="high" bgcolor="#FFFFFF" wmode="window" menu="false" ></embed>
</object>
</p>
<p><a href="https://sites.google.com/site/riafiles/SparkMultiColSortableDataGrid.fxp?attredirects=0&#038;d=1">原始檔案下載</a></p>
<p>Related posts:<ol>
<li><a href='http://blog.richmediaplus.com/2011/08/spark-richeditabletext-maxchars-issue/' rel='bookmark' title='Flex 4.5 Spark RichEditableText maxChars 與輸入法問題'>Flex 4.5 Spark RichEditableText maxChars 與輸入法問題</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/2009/04/create-trail-information-and-expired-date-in-actionscript3-and-flex3/' rel='bookmark' title='Create Trail Information &amp; Expired Date in ActionScript3 &amp; Flex'>Create Trail Information &#038; Expired Date in ActionScript3 &#038; Flex</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://blog.richmediaplus.com/2011/09/spark-multi-column-sortable-datagrid/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Flash/Flex 移动端开发 之 DPI</title>
		<link>http://blog.richmediaplus.com/2011/09/flash-flex-mobile-dev-dpi/</link>
		<comments>http://blog.richmediaplus.com/2011/09/flash-flex-mobile-dev-dpi/#comments</comments>
		<pubDate>Fri, 02 Sep 2011 03:47:43 +0000</pubDate>
		<dc:creator>Alvin / Aedis.Ju</dc:creator>
				<category><![CDATA[Flash/Flex Mobile Dev]]></category>
		<category><![CDATA[Mobile Dev]]></category>
		<category><![CDATA[Adobe Flex]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[移动端开发]]></category>

		<guid isPermaLink="false">http://blog.richmediaplus.com/?p=814</guid>
		<description><![CDATA[DPI是Dots Per Inch的缩写，中文即每英寸点数，或者每英寸像素数。 100 * 100的图片 在DPI为100的地方就是1英寸*1英寸的大小 在DPI为200的地方就是0.5英寸*0.5英寸的大小 在iPhone4(DPI为326)就是0.3英寸*0.3英寸左右的大小 同样，只要是我们看得到的东西，包括图片，文字，边框粗细，都会在DPI的不同下会看到不一样的大小。 DPI在Flash中可以通过 flash.system.Capabilities.screenDPI 可以获得当前移动设备的DPI。在Flex可以通过 FlexGlobals.topLevelApplication.runtimeDPI 设备的近似DPI，只有160、240、320这3个值。 为什么只有这3个DPI值呢？ 先看看各大厂商流行的DPI。 表 1. 移动设备分辨率、大小和 DPI 值的示例 生产商 设备 分辨率 (px) 屏幕对角线长度(in) DPI Apple iPhone 4, iPod 4 960 x 640 3.5 326 Apple iPad 1, iPad 2 1024 x 768 9.7 132 BlackBerry PlayBook 1024 x 600 7 170 HTC Evo 800 [...]
Related posts:<ol>
<li><a href='http://blog.richmediaplus.com/2011/06/flash-flex-mobile-dev-background/' rel='bookmark' title='Flash/Flex 移动端开发 之 现状'>Flash/Flex 移动端开发 之 现状</a></li>
<li><a href='http://blog.richmediaplus.com/2011/06/flash-flex-mobile-dev-ready-components/' rel='bookmark' title='Flash/Flex 移动端开发 之 Flex就绪核心组件'>Flash/Flex 移动端开发 之 Flex就绪核心组件</a></li>
<li><a href='http://blog.richmediaplus.com/2011/10/running-panda-share-study/' rel='bookmark' title='《Running Panda》移动游戏开发心得分享 &#8211; 入门'>《Running Panda》移动游戏开发心得分享 &#8211; 入门</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>DPI是Dots Per Inch的缩写，中文即每英寸点数，或者每英寸像素数。<br />
100 * 100的图片<br />
在DPI为100的地方就是1英寸*1英寸的大小<br />
在DPI为200的地方就是0.5英寸*0.5英寸的大小<br />
在iPhone4(DPI为326)就是0.3英寸*0.3英寸左右的大小</p>
<p>同样，只要是我们看得到的东西，包括图片，文字，边框粗细，都会在DPI的不同下会看到不一样的大小。</p>
<p>DPI在Flash中可以通过 flash.system.Capabilities.screenDPI 可以获得当前移动设备的DPI。在Flex可以通过 FlexGlobals.topLevelApplication.runtimeDPI 设备的近似DPI，只有160、240、320这3个值。<br />
为什么只有这3个DPI值呢？<br />
先看看各大厂商流行的DPI。</p>
<p><strong>表</strong><strong> 1.</strong> 移动设备分辨率、大小和 DPI 值的示例</p>
<table border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td width="144"><strong>生产商</strong></td>
<td width="130"><strong>设备</strong></td>
<td width="137"><strong>分辨率</strong><strong> (px)</strong></td>
<td width="109"><strong>屏幕对角线长度</strong><strong>(in)</strong></td>
<td width="119"><strong>DPI</strong></td>
</tr>
<tr>
<td width="144">Apple</td>
<td width="130">iPhone 4, iPod 4</td>
<td width="137">960 x 640</td>
<td width="109">3.5</td>
<td width="119">326</td>
</tr>
<tr>
<td width="144">Apple</td>
<td width="130">iPad 1, iPad 2</td>
<td width="137">1024 x 768</td>
<td width="109">9.7</td>
<td width="119">132</td>
</tr>
<tr>
<td width="144">BlackBerry</td>
<td width="130">PlayBook</td>
<td width="137">1024 x 600</td>
<td width="109">7</td>
<td width="119">170</td>
</tr>
<tr>
<td width="144">HTC</td>
<td width="130">Evo</td>
<td width="137">800 x 480</td>
<td width="109">4.3</td>
<td width="119">217</td>
</tr>
<tr>
<td width="144">Motorola</td>
<td width="130">Atrix</td>
<td width="137">960 x 540</td>
<td width="109">4</td>
<td width="119">275</td>
</tr>
<tr>
<td width="144">Motorola</td>
<td width="130">Xoom</td>
<td width="137">1280 x 800</td>
<td width="109">10.1</td>
<td width="119">150</td>
</tr>
<tr>
<td width="144">Samsung</td>
<td width="130">Galaxy Tab</td>
<td width="137">1024 x 600</td>
<td width="109">7</td>
<td width="119">170</td>
</tr>
</tbody>
</table>
<p>在移动设备和桌面设备上，每一家的DPI实际值都不一样，但是综合看起来，他们都非常接近于160， 240， 320 这3个值。<br />
而且通过这3个值也能很好的把握住位图缩放的尺寸，不太容易出现锯齿的情况。</p>
<p>Related posts:<ol>
<li><a href='http://blog.richmediaplus.com/2011/06/flash-flex-mobile-dev-background/' rel='bookmark' title='Flash/Flex 移动端开发 之 现状'>Flash/Flex 移动端开发 之 现状</a></li>
<li><a href='http://blog.richmediaplus.com/2011/06/flash-flex-mobile-dev-ready-components/' rel='bookmark' title='Flash/Flex 移动端开发 之 Flex就绪核心组件'>Flash/Flex 移动端开发 之 Flex就绪核心组件</a></li>
<li><a href='http://blog.richmediaplus.com/2011/10/running-panda-share-study/' rel='bookmark' title='《Running Panda》移动游戏开发心得分享 &#8211; 入门'>《Running Panda》移动游戏开发心得分享 &#8211; 入门</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://blog.richmediaplus.com/2011/09/flash-flex-mobile-dev-dpi/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Flex Compiler 編譯參數嵌入外部資源技巧</title>
		<link>http://blog.richmediaplus.com/2011/08/mxmlc-define-embed-source/</link>
		<comments>http://blog.richmediaplus.com/2011/08/mxmlc-define-embed-source/#comments</comments>
		<pubDate>Sun, 28 Aug 2011 03:58:25 +0000</pubDate>
		<dc:creator>Ticore Shih</dc:creator>
				<category><![CDATA[ActionScript3]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[Adobe Flex]]></category>

		<guid isPermaLink="false">http://blog.richmediaplus.com/?p=812</guid>
		<description><![CDATA[大家好，我是 Ticore，這次來介紹關於 Flex Compiler 編譯參數與嵌入外部資源的技巧 看到有人問 Embed source 是否能使用變數 一般人直覺的反應大概都是不可能，因為 Embed 是編譯期就決定了 但是對於編譯期的變數呢? 測試之後發現是可行的 Flex Compiler &#8211; mxmlc 有支援定義變數的功能 最常見的是用來條件式編譯除錯 Stupid Flex MXMLC Compiler Tricks Part 1: Conditional Compiling 除了 Boolean 之外，它也是可以用來定義字串的 並且能夠指定到 Embed source 上 以下是完整的測試範例： package &#123; import flash.display.Sprite; &#160; public class EmbedTest extends Sprite &#123; &#160; config::EMBED_SRC &#123; &#91;Embed&#40;source=config::EMBED_SRC&#41;&#93; public var Cls:Class; [...]
Related posts:<ol>
<li><a href='http://blog.richmediaplus.com/2011/11/custom-flex-cursor-instance/' rel='bookmark' title='自訂 Flex 滑鼠游標實體'>自訂 Flex 滑鼠游標實體</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>
<li><a href='http://blog.richmediaplus.com/2011/06/flex-spark-preloader-disappear/' rel='bookmark' title='解決 Flex 4.x 下載進度不出現的問題'>解決 Flex 4.x 下載進度不出現的問題</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>大家好，我是 Ticore，這次來介紹關於 Flex Compiler 編譯參數與嵌入外部資源的技巧<br />
看到有人問 Embed source 是否能使用變數<br />
一般人直覺的反應大概都是不可能，因為 Embed 是編譯期就決定了<br />
但是對於編譯期的變數呢? 測試之後發現是可行的</p>
<p>Flex Compiler &#8211; mxmlc 有支援定義變數的功能<br />
最常見的是用來條件式編譯除錯<br />
<a href="http://www.ditdahgames.com/2011/07/stupid-flex-mxmlc-compiler-tricks-part-1-conditional-compiling/">Stupid Flex MXMLC Compiler Tricks Part 1: Conditional Compiling</a></p>
<p>除了 Boolean 之外，它也是可以用來定義字串的<br />
並且能夠指定到 Embed source 上<br />
以下是完整的測試範例：</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #9900cc; font-weight: bold;">package</span> <span style="color: #000000;">&#123;</span>
	<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.display</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">Sprite</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
	<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #9900cc; font-weight: bold;">class</span> EmbedTest <span style="color: #0033ff; font-weight: bold;">extends</span> <span style="color: #004993;">Sprite</span> <span style="color: #000000;">&#123;</span>
&nbsp;
		config<span style="color: #000066; font-weight: bold;">::</span>EMBED_SRC <span style="color: #000000;">&#123;</span>
			<span style="color: #000000;">&#91;</span>Embed<span style="color: #000000;">&#40;</span><span style="color: #004993;">source</span>=config<span style="color: #000066; font-weight: bold;">::</span>EMBED_SRC<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span>
			<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #6699cc; font-weight: bold;">var</span> Cls<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Class</span><span style="color: #000066; font-weight: bold;">;</span>
		<span style="color: #000000;">&#125;</span>
&nbsp;
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> EmbedTest<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
			config<span style="color: #000066; font-weight: bold;">::</span>EMBED_SRC <span style="color: #000000;">&#123;</span>
				<span style="color: #004993;">addChild</span><span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">new</span> Cls<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
			<span style="color: #000000;">&#125;</span>
		<span style="color: #000000;">&#125;</span>
&nbsp;
	<span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>mxmlc 編譯參數寫法為</p>
<p><code>-define+=config::EMBED_SRC,"'OrigamiMurex.jpg'"</code></p>
<p>假如不想要嵌入外部資源了，改成以下寫法<br />
Class 內相關程式碼區塊都會被 disable</p>
<p><code>-define+=config::EMBED_SRC,false</code></p>
<p>Related posts:<ol>
<li><a href='http://blog.richmediaplus.com/2011/11/custom-flex-cursor-instance/' rel='bookmark' title='自訂 Flex 滑鼠游標實體'>自訂 Flex 滑鼠游標實體</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>
<li><a href='http://blog.richmediaplus.com/2011/06/flex-spark-preloader-disappear/' rel='bookmark' title='解決 Flex 4.x 下載進度不出現的問題'>解決 Flex 4.x 下載進度不出現的問題</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://blog.richmediaplus.com/2011/08/mxmlc-define-embed-source/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Flex 4.5 Spark RichEditableText maxChars 與輸入法問題</title>
		<link>http://blog.richmediaplus.com/2011/08/spark-richeditabletext-maxchars-issue/</link>
		<comments>http://blog.richmediaplus.com/2011/08/spark-richeditabletext-maxchars-issue/#comments</comments>
		<pubDate>Sat, 06 Aug 2011 02:50:26 +0000</pubDate>
		<dc:creator>Ticore Shih</dc:creator>
				<category><![CDATA[ActionScript3]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[Adobe Flex]]></category>
		<category><![CDATA[Adobe Flex4]]></category>
		<category><![CDATA[TLF]]></category>

		<guid isPermaLink="false">http://blog.richmediaplus.com/?p=807</guid>
		<description><![CDATA[當在 TextInput, TextArea 等文字組件設定 maxChars 最大字數屬性 使用中文輸入法打了數個字到文字佇列上，超過最大限制字數 然後用 Ctrl + Space 切換輸入法或是按下 Enter 方式輸入文字 結果會發現其它 Binding 到 text 屬性的目標無法取得正確的 text 字串 之後再利用按鈕事件 trace 組件的 text 屬性也是取到錯誤的字串資料 來回 trace 好多程式碼位置之後，發現問題主要是出在 RichEditableText 組件上 不過由於問題原因非常複雜，所以要分成很多段落先解釋一些 TLF 與文字組件運作方式 為什麼要花這麼大力氣找原因? 除了解決問題之外，主要還想要了解一下 TLF 文字引擎的運作方式 令我最驚訝的是，輸入法待選文字佇列功能，居然是 TLF 內建，完全用 AS3 寫的！ 相關 Bug Report http://bugs.adobe.com/jira/browse/SDK-28999 http://www.fxug.net/modules/xhnewbb/viewtopic.php?topic_id=4338 RichEditableText maxChars 與輸入法問題測試程式： &#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/09/spark-multi-column-sortable-datagrid/' rel='bookmark' title='Spark 多重欄位排序的 DataGrid'>Spark 多重欄位排序的 DataGrid</a></li>
<li><a href='http://blog.richmediaplus.com/2009/03/htmlformatforreducedatabasestorageinclient/' rel='bookmark' title='htmlFormat for Reduce DataBase Storage in Client'>htmlFormat for Reduce DataBase Storage in Client</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>
</ol>]]></description>
			<content:encoded><![CDATA[<p>當在 TextInput, TextArea 等文字組件設定 maxChars 最大字數屬性<br />
使用中文輸入法打了數個字到文字佇列上，超過最大限制字數<br />
然後用 Ctrl + Space 切換輸入法或是按下 Enter 方式輸入文字<br />
結果會發現其它 Binding 到 text 屬性的目標無法取得正確的 text 字串<br />
之後再利用按鈕事件 trace 組件的 text 屬性也是取到錯誤的字串資料</p>
<p>來回 trace 好多程式碼位置之後，發現問題主要是出在 RichEditableText 組件上<br />
不過由於問題原因非常複雜，所以要分成很多段落先解釋一些 TLF 與文字組件運作方式</p>
<p>為什麼要花這麼大力氣找原因?<br />
除了解決問題之外，主要還想要了解一下 TLF 文字引擎的運作方式<br />
令我最驚訝的是，輸入法待選文字佇列功能，居然是 TLF 內建，完全用 AS3 寫的！</p>
<p>相關 Bug Report</p>
<p>http://bugs.adobe.com/jira/browse/SDK-28999</p>
<p>http://www.fxug.net/modules/xhnewbb/viewtopic.php?topic_id=4338</p>
<p>RichEditableText maxChars 與輸入法問題測試程式：</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> fontSize=<span style="color: #ff0000;">&quot;14&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:HorizontalLayout</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>
&nbsp;
 <span style="color: #000000;"><span style="color: #7400FF;">&lt;s:VGroup</span> gap=<span style="color: #ff0000;">&quot;12&quot;</span><span style="color: #7400FF;">&gt;</span></span>
  <span style="color: #000000;"><span style="color: #7400FF;">&lt;s:Label</span> text=<span style="color: #ff0000;">&quot;TextInput&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;txt1&quot;</span> contentBackgroundColor=<span style="color: #ff0000;">&quot;#DDDDDD&quot;</span></span>
<span style="color: #000000;">    maxChars=<span style="color: #ff0000;">&quot;3&quot;</span> widthInChars=<span style="color: #ff0000;">&quot;8&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
  <span style="color: #000000;"><span style="color: #7400FF;">&lt;s:TextInput</span> text=<span style="color: #ff0000;">&quot;{txt1.text}&quot;</span><span style="color: #7400FF;">/&gt;</span></span>
  <span style="color: #000000;"><span style="color: #7400FF;">&lt;s:Label</span> text=<span style="color: #ff0000;">&quot;txt1.text: {txt1.text}&quot;</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;trace(txt1.text);&quot;</span> click=<span style="color: #ff0000;">&quot;trace(txt1.text);&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>
&nbsp;
 <span style="color: #000000;"><span style="color: #7400FF;">&lt;s:VGroup</span> gap=<span style="color: #ff0000;">&quot;12&quot;</span><span style="color: #7400FF;">&gt;</span></span>
  <span style="color: #000000;"><span style="color: #7400FF;">&lt;s:Label</span> text=<span style="color: #ff0000;">&quot;TextArea&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;txt2&quot;</span> contentBackgroundColor=<span style="color: #ff0000;">&quot;#DDDDDD&quot;</span></span>
<span style="color: #000000;">    maxChars=<span style="color: #ff0000;">&quot;3&quot;</span> heightInLines=<span style="color: #ff0000;">&quot;1&quot;</span> widthInChars=<span style="color: #ff0000;">&quot;8&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
  <span style="color: #000000;"><span style="color: #7400FF;">&lt;s:TextInput</span> text=<span style="color: #ff0000;">&quot;{txt2.text}&quot;</span><span style="color: #7400FF;">/&gt;</span></span>
  <span style="color: #000000;"><span style="color: #7400FF;">&lt;s:Label</span> text=<span style="color: #ff0000;">&quot;txt2.text: {txt2.text}&quot;</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;trace(txt2.text);&quot;</span> click=<span style="color: #ff0000;">&quot;trace(txt2.text);&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>
&nbsp;
 <span style="color: #000000;"><span style="color: #7400FF;">&lt;s:VGroup</span> gap=<span style="color: #ff0000;">&quot;12&quot;</span><span style="color: #7400FF;">&gt;</span></span>
  <span style="color: #000000;"><span style="color: #7400FF;">&lt;s:Label</span> text=<span style="color: #ff0000;">&quot;RichEditableText&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
  <span style="color: #000000;"><span style="color: #7400FF;">&lt;s:RichEditableText</span> id=<span style="color: #ff0000;">&quot;txt3&quot;</span> backgroundColor=<span style="color: #ff0000;">&quot;#DDDDDD&quot;</span></span>
<span style="color: #000000;">    paddingLeft=<span style="color: #ff0000;">&quot;4&quot;</span> paddingRight=<span style="color: #ff0000;">&quot;4&quot;</span> paddingTop=<span style="color: #ff0000;">&quot;4&quot;</span> paddingBottom=<span style="color: #ff0000;">&quot;4&quot;</span></span>
<span style="color: #000000;">    maxChars=<span style="color: #ff0000;">&quot;3&quot;</span> heightInLines=<span style="color: #ff0000;">&quot;1&quot;</span> widthInChars=<span style="color: #ff0000;">&quot;8&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
  <span style="color: #000000;"><span style="color: #7400FF;">&lt;s:TextInput</span> text=<span style="color: #ff0000;">&quot;{txt3.text}&quot;</span><span style="color: #7400FF;">/&gt;</span></span>
  <span style="color: #000000;"><span style="color: #7400FF;">&lt;s:Label</span> text=<span style="color: #ff0000;">&quot;txt3.text: {txt3.text}&quot;</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;trace(txt3.text);&quot;</span> click=<span style="color: #ff0000;">&quot;trace(txt3.text);&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:Application</span><span style="color: #7400FF;">&gt;</span></span></pre></div></div>

<p><strong>※ RichEditableText 內部 TLF 文字管理</strong><br />
RichEditableText 本身並不直接控制文字表現<br />
而是透過內部一個 TLF TextContainerManager 實體<br />
負責表現、捲動、編輯文字以及文字輸入法佇列<br />
每當文字發生變動<br />
TextContainerManager 有三個事件會依序發出，當然還有其它的 Damage, Composition 等事件</p>
<p>FlowOperationEvent.FLOW_OPERATION_BEGIN<br />
FlowOperationEvent.FLOW_OPERATION_END<br />
FlowOperationEvent.FLOW_OPERATION_COMPLETE</p>
<p>RichEditable 內三個私有偵聽函式負責處理</p>
<p>textContainerManager_flowOperationBeginHandler<br />
 處理完立即發出 TextOperationEvent.CHANGING 事件</p>
<p>textContainerManager_flowOperationEndHandler</p>
<p>textContainerManager_flowOperationCompleteHandler<br />
 處理完立即發出 TextOperationEvent.CHANGE 事件</p>
<p>在 textContainerManager_flowOperationBeginHandler 內<br />
也會檢查插入文字 + 原本文字總長是否超出 maxChars，並加以裁切<br />
輸入法問題就是出在這裡</p>
<p><strong>※ RichEditableText.text 屬性的內部 cache</strong><br />
RichEditableText 內部用一個私有變數存放 Plain Text 叫做 _text<br />
每當 textFlow, content 被重新指定或是 damage 事件發生時，_text 會被重設為 null<br />
假如取用 text 時 _text 為 null，會從 TextFlow 重新 export plain text 並存放到 _text</p>
<p><strong>※ 從 TextFlow 取得 Plain 文字的方式</strong><br />
var staticPlainTextExporter:ITextExporter =<br />
  TextConverter.getExporter(TextConverter.PLAIN_TEXT_FORMAT);<br />
var txt:String = staticPlainTextExporter.export(textFlow, ConversionType.STRING_TYPE) as String;</p>
<p>// 或是</p>
<p>textFlow.getText();</p>
<p><strong>※ RichEditableText maxChars 與輸入法問題的成因</strong><br />
IME 輸入法輸入文字到佇列，然後確認文字是一連串複雜的動作<br />
由於佇列文字是由 TLF 負責表現<br />
當確認佇列文字時，必須先銷毀 TLF 佇列文字<br />
然後復原畫面到不包含佇列文字的狀況<br />
最後再合併輸入輸入文字</p>
<p>以上動作會在 FlowOperationEvent.FLOW_OPERATION_BEGIN 事件後開始進行<br />
預設情況下，由於輸入佇列文字動作比較複雜<br />
TLF EditManager 不會立刻完成所有的動作，而是會透過影格事件分批完成<br />
然後才發出 FlowOperationEvent.FLOW_OPERATION_END 事件<br />
導致此時從 TextFlow 取得的文字並非最後的結果</p>
<p>假如又要檢查 text.length 是否超過 maxChars 的話<br />
會觸發 export plain text 存到 _text 快取<br />
之後完全沒有更新的 _text 快取機會<br />
導致取到的 text 資料都是舊的</p>
<p><strong>※ 為什麼 Flex 4.0 沒有這問題</strong><br />
基本上 RichEditableText 沒有很大差異<br />
而 Flex 4.0 是使用 TLF 1.1，Flex 4.5 是使用 TLF 2.0<br />
主要是 TLF 1.1 TextContainerManager 最後完成所有操作之後<br />
都會再多發一次 Damage 事件，讓 _text 快取被清掉了</p>
<p><strong>※ 強迫 TLF EditManager 立刻完成所有的動作的方式</strong><br />
(Spark ComboBox 會設定 batchTextInput = false 所以才避開了這個問題)</p>
<p>RichEditableText Class：</p>
<p>/**<br />
 *  @private<br />
 *  The TLF edit manager will batch all inserted text until the next<br />
 *  enter frame event.  This includes text inserted via the GUI as well<br />
 *  as api calls to EditManager.insertText().  Set this to false if you<br />
 *  want every keystroke to be inserted into the text immediately which will<br />
 *  result in a TextOperationEvent.CHANGE event for each character.  One<br />
 *  place this is needed is for the type-ahead feature of the editable combo<br />
 *  box.<br />
 */<br />
mx_internal var batchTextInput:Boolean = true;<br />
以上屬性會在 RichEditableTextContainerManager createEditManager 時<br />
設定到 EditManager 上<br />
editManager.allowDelayedOperations = textDisplay.batchTextInput;</p>
<p><strong>※ 問題解決方式</strong><br />
方式 1.<br />
修改 RichEditableText 內的 textContainerManager_flowOperationBeginHandler 函式<br />
取用完 text.length 之後，指定 _text 為 null</p>
<p>if (maxChars != 0) {<br />
    var length1:int = text.length &#8211; delLen;<br />
    var length2:int = textToInsert.length;<br />
    if (length1 + length2 > maxChars)<br />
        textToInsert = textToInsert.substr(0, maxChars &#8211; length1);<br />
    _text = null;<br />
}<br />
方式 2.<br />
在 RichEditableText 組件 change 事件上，重新指定 textFlow，強迫更新 _text 快取</p>
<p>var tf:TextFlow = event.target.textFlow;<br />
event.target.textFlow = new TextFlow();<br />
event.target.textFlow = tf;<br />
Spark TextInput, TextArea 可以在自訂 Skin 裡面添加以上程式</p>
<p>方式 3. (建議)<br />
在 RichEditableText 組件 preinitialize 事件中，設定 batchTextInput 為 false</p>
<p>event.target.mx_internal::batchTextInput = false;<br />
Spark TextInput, TextArea 可以在自訂 Skin 裡面添加以上程式</p>
<p>Related posts:<ol>
<li><a href='http://blog.richmediaplus.com/2011/09/spark-multi-column-sortable-datagrid/' rel='bookmark' title='Spark 多重欄位排序的 DataGrid'>Spark 多重欄位排序的 DataGrid</a></li>
<li><a href='http://blog.richmediaplus.com/2009/03/htmlformatforreducedatabasestorageinclient/' rel='bookmark' title='htmlFormat for Reduce DataBase Storage in Client'>htmlFormat for Reduce DataBase Storage in Client</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>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://blog.richmediaplus.com/2011/08/spark-richeditabletext-maxchars-issue/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>將 Box2D Alchemy WCK 打包為 SWC 類別庫</title>
		<link>http://blog.richmediaplus.com/2011/07/box2d-wck-swc-flash/</link>
		<comments>http://blog.richmediaplus.com/2011/07/box2d-wck-swc-flash/#comments</comments>
		<pubDate>Fri, 08 Jul 2011 02:04:45 +0000</pubDate>
		<dc:creator>Ticore Shih</dc:creator>
				<category><![CDATA[ActionScript Library]]></category>
		<category><![CDATA[ActionScript3]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[Adobe Flex]]></category>
		<category><![CDATA[Box2D]]></category>

		<guid isPermaLink="false">http://blog.richmediaplus.com/?p=795</guid>
		<description><![CDATA[最近開始需要用到物理引擎 網路上有好幾套 Flash 物理引擎 比較多人用、資料比較豐富的似乎是從 C 移植過來的 Box2D 同樣是移植過來的版本居然還有分兩種 Box2D Flash AS3 與 Box2D Alchemy WCK Box2D Flash AS3 整個是純 AS3 寫成的 Box2D Alchemy WCK 是直接拿 Box2D C 程式，透過 Alchemy 編譯為 Flash SWC 然後加上其它 AS3 Wrapper Class 來的 兩種版本大略使用過之後發現 Box2D Alchemy WCK 有許多優點 執行效能較佳 與 Box2D 原版 API 接近，假如原版更新了，也可以自己架設 Alchemy 更新到 Flash 版 提供了很多輔助類別可以使用，譬如能夠作到各種形狀重力場等 與 [...]
Related posts:<ol>
<li><a href='http://blog.richmediaplus.com/2010/07/richmediaplus-utils-alertutils/' rel='bookmark' title='richmediaplus.utils.AlertUtils'>richmediaplus.utils.AlertUtils</a></li>
<li><a href='http://blog.richmediaplus.com/2011/03/warning-class-close-does-not-extend-the-definebits-asset-base-class-flash-display-bitmap/' rel='bookmark' title='Warning: Class &#8216;Close&#8217; does not extend the &#8216;DefineBits&#8217; asset base class &#8216;flash.display.Bitmap&#8217;.'>Warning: Class &#8216;Close&#8217; does not extend the &#8216;DefineBits&#8217; asset base class &#8216;flash.display.Bitmap&#8217;.</a></li>
<li><a href='http://blog.richmediaplus.com/2011/10/robotlegs-module-issue/' rel='bookmark' title='RobotLegs Module 開發上的問題'>RobotLegs Module 開發上的問題</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>最近開始需要用到物理引擎<br />
網路上有好幾套 Flash 物理引擎<br />
比較多人用、資料比較豐富的似乎是從 C 移植過來的 Box2D<br />
同樣是移植過來的版本居然還有分兩種<br />
<a href="http://box2dflash.sourceforge.net/">Box2D Flash AS3</a> 與 <a href="http://www.sideroller.com/wck/">Box2D Alchemy WCK</a><br />
Box2D Flash AS3 整個是純 AS3 寫成的<br />
Box2D Alchemy WCK 是直接拿 Box2D C 程式，透過 Alchemy 編譯為 Flash SWC<br />
然後加上其它 AS3 Wrapper Class 來的<br />
兩種版本大略使用過之後發現 Box2D Alchemy WCK 有許多優點</p>
<ul>
<li>執行效能較佳</li>
<li>與 Box2D 原版 API 接近，假如原版更新了，也可以自己架設 Alchemy 更新到 Flash 版</li>
<li>提供了很多輔助類別可以使用，譬如能夠作到各種形狀重力場等</li>
<li>與 Flash IDE 完美整合在一起，甚至只要用拖拉的方式就可以建立好需要的物理場景</li>
</ul>
<p>唯一的缺點只有檔案較大，沒有提供單一打包好的 SWC，導致編譯速度太慢問題<br />
用了之後一定會占掉 300kb 左右大小，這或許也不算很大<br />
不過編譯速度太慢真的很傷腦筋<br />
所以本篇文章的目的就是要把整個 Project 打包為單一 SWC<br />
如此一來，編譯速度就會大幅提升，也能很容易的拿到 Flash Builder 內使用</p>
<p>當我實際開始著手這樣工作之後，才發現遇到很多問題<br />
也懶得一一解釋原因了<br />
主要的步驟如下：</p>
<ol>
<li>開一個空白的 Flex Library Project &#8211; Box2DAlchemyLib</li>
<li>將 Box2D.swc 加入到 lib path</li>
<li>將所有的 AS3 Class 放置到 Flex Lib src 下，修正未宣告型別、存取修飾子等語法問題</li>
<p>e.g. /src/wck/WavesEffect.as -> /src/extra/WavesEffect.as</p>
<li>於空的 Package 下放置空白 Dummy Class</li>
<p>e.g. /src/Box2DAS/Cls.as</ol>
<p>以上就能產生出可以同時給 Flash/Flex 用的 SWC 類別庫了<br />
假如想要把 Demo.fla 套用新的 SWC 類別庫<br />
修改步驟如下：</p>
<ol>
<li>修改 fla AS3 Setting，path 加入 Box2DAlchemyLib.swc，並取消發布 SWC</li>
<li>修改 MovieClip 設定</li>
<p><code>GravityCapsule Symbol<br />
  Class: GravityCapsule<br />
  Base Class: gravity.GravityCapsule</p>
<p> GravityLinear Symbol<br />
  Class: GravityLinear<br />
  Base Class: gravity.GravityLinear</p>
<p> GravityRadial Symbol<br />
  Class: GravityRadial<br />
  Base Class: gravity.GravityRadial</p>
<p> GravitySine Symbol<br />
  Class: GravitySine<br />
  Base Class: gravity.GravitySine</code>
</ol>
<p>修改完之後，編譯時間從原本 30 秒大幅縮短到 9 秒呢<br />
這是我修改完之後的 <a href="https://sites.google.com/site/riafiles/Box2DAlchemyLib_20110622.fxpl?attredirects=0&#038;d=1">Box2D WCK Library Project</a>，從 2011-06-15 那版改的</p>
<p>Related posts:<ol>
<li><a href='http://blog.richmediaplus.com/2010/07/richmediaplus-utils-alertutils/' rel='bookmark' title='richmediaplus.utils.AlertUtils'>richmediaplus.utils.AlertUtils</a></li>
<li><a href='http://blog.richmediaplus.com/2011/03/warning-class-close-does-not-extend-the-definebits-asset-base-class-flash-display-bitmap/' rel='bookmark' title='Warning: Class &#8216;Close&#8217; does not extend the &#8216;DefineBits&#8217; asset base class &#8216;flash.display.Bitmap&#8217;.'>Warning: Class &#8216;Close&#8217; does not extend the &#8216;DefineBits&#8217; asset base class &#8216;flash.display.Bitmap&#8217;.</a></li>
<li><a href='http://blog.richmediaplus.com/2011/10/robotlegs-module-issue/' rel='bookmark' title='RobotLegs Module 開發上的問題'>RobotLegs Module 開發上的問題</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://blog.richmediaplus.com/2011/07/box2d-wck-swc-flash/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>解決 Flex 4.x 下載進度不出現的問題</title>
		<link>http://blog.richmediaplus.com/2011/06/flex-spark-preloader-disappear/</link>
		<comments>http://blog.richmediaplus.com/2011/06/flex-spark-preloader-disappear/#comments</comments>
		<pubDate>Wed, 29 Jun 2011 10:39:22 +0000</pubDate>
		<dc:creator>Ticore Shih</dc:creator>
				<category><![CDATA[ActionScript3]]></category>
		<category><![CDATA[Adobe]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[Adobe Flex]]></category>
		<category><![CDATA[Adobe Flex4]]></category>

		<guid isPermaLink="false">http://blog.richmediaplus.com/?p=791</guid>
		<description><![CDATA[有人問 Flex 4, 4.5 Spark 的 Download Progress Bar 不出現的問題 Adobe 討論板上也有人問 原因大略是因為 Flex 4, 4.5 提高了出現的門檻 原本 MX 版 Progress Bar 是要超過 300ms 才會出現 Spark 版 Progress Bar 要超過 700ms 且下載進度未超過 50% 才會出現 條件相當嚴苛，導致一般的小 Flex App 都看不到下載進度條了 解決的方式不難，自己繼承 SparkDownloadProgressBar 並覆寫 showDisplayForDownloading package &#123; import flash.events.ProgressEvent; import mx.preloaders.SparkDownloadProgressBar; &#160; public class MySparkDownloadProgressBar extends SparkDownloadProgressBar &#123; [...]
Related posts:<ol>
<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>
<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/05/flex-3-style-module/' rel='bookmark' title='Flex 3 Style Module'>Flex 3 Style Module</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>有人問 <a href="http://bbs.9ria.com/viewthread.php?tid=86656&#038;rpid=806988&#038;ordertype=0&#038;page=1#pid806988">Flex 4, 4.5 Spark 的 Download Progress Bar 不出現的問題</a><br />
<a href="http://forums.adobe.com/message/3700786">Adobe 討論板上也有人問</a> 原因大略是因為 Flex 4, 4.5 提高了出現的門檻<br />
原本 MX 版 Progress Bar 是要超過 300ms 才會出現<br />
Spark 版 Progress Bar 要超過 700ms 且下載進度未超過 50% 才會出現<br />
條件相當嚴苛，導致一般的小 Flex App 都看不到下載進度條了</p>
<p>解決的方式不難，自己繼承 SparkDownloadProgressBar 並覆寫 showDisplayForDownloading</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #9900cc; font-weight: bold;">package</span> <span style="color: #000000;">&#123;</span>
 <span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.events</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">ProgressEvent</span><span style="color: #000066; font-weight: bold;">;</span>
 <span style="color: #0033ff; font-weight: bold;">import</span> mx<span style="color: #000066; font-weight: bold;">.</span>preloaders<span style="color: #000066; font-weight: bold;">.</span>SparkDownloadProgressBar<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> MySparkDownloadProgressBar <span style="color: #0033ff; font-weight: bold;">extends</span> SparkDownloadProgressBar <span style="color: #000000;">&#123;</span>
&nbsp;
  override <span style="color: #0033ff; font-weight: bold;">protected</span> <span style="color: #339966; font-weight: bold;">function</span> showDisplayForDownloading<span style="color: #000000;">&#40;</span>elapsedTime<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">int</span><span style="color: #000066; font-weight: bold;">,</span> event<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">ProgressEvent</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Boolean</span> <span style="color: #000000;">&#123;</span>
   <span style="color: #009966; font-style: italic;">/*/</span>
   <span style="color: #004993;">trace</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;showDisplayForDownloading: elapsedTime = &quot;</span> <span style="color: #000066; font-weight: bold;">+</span> elapsedTime<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
   <span style="color: #004993;">trace</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;showDisplayForDownloading:&quot;</span> <span style="color: #000066; font-weight: bold;">+</span> event<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">bytesLoaded</span> <span style="color: #000066; font-weight: bold;">+</span> <span style="color: #990000;">&quot; &quot;</span> <span style="color: #000066; font-weight: bold;">+</span>
    event<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">bytesTotal</span> <span style="color: #000066; font-weight: bold;">+</span> <span style="color: #990000;">&quot; &quot;</span> <span style="color: #000066; font-weight: bold;">+</span> <span style="color: #000000;">&#40;</span>event<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">bytesLoaded</span> <span style="color: #000066; font-weight: bold;">&lt;</span> event<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">bytesTotal</span> <span style="color: #000066; font-weight: bold;">/</span> <span style="color: #000000; font-weight:bold;">2</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
   <span style="color: #009900; font-style: italic;">//*/</span>
&nbsp;
   <span style="color: #0033ff; font-weight: bold;">return</span> elapsedTime <span style="color: #000066; font-weight: bold;">&gt;</span> <span style="color: #000000; font-weight:bold;">100</span><span style="color: #000066; font-weight: bold;">;</span>
   <span style="color: #009900; font-style: italic;">// return elapsedTime &gt; 700 &amp;&amp; event.bytesLoaded &lt; event.bytesTotal / 2;</span>
  <span style="color: #000000;">&#125;</span>
 <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>然後在 Application 替換為自訂的 Preloader 就好了：</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>
<span style="color: #000000;">  preloader=<span style="color: #ff0000;">&quot;MySparkDownloadProgressBar&quot;</span><span style="color: #7400FF;">&gt;</span></span>
&nbsp;
 <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>
&nbsp;
 <span style="color: #000000;"><span style="color: #7400FF;">&lt;s:Button</span> label=<span style="color: #ff0000;">&quot;Button&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
&nbsp;
<span style="color: #000000;"><span style="color: #7400FF;">&lt;/s:Application</span><span style="color: #7400FF;">&gt;</span></span></pre></div></div>

<p>假如想要調整 MX 版 Progress Bar 出現門檻，方法也是類似<br />
只是要覆寫的 function 不一樣</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #9900cc; font-weight: bold;">package</span> <span style="color: #000000;">&#123;</span>
 <span style="color: #0033ff; font-weight: bold;">import</span> mx<span style="color: #000066; font-weight: bold;">.</span>preloaders<span style="color: #000066; font-weight: bold;">.</span>DownloadProgressBar<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> MyDownloadProgressBar <span style="color: #0033ff; font-weight: bold;">extends</span> DownloadProgressBar <span style="color: #000000;">&#123;</span>
&nbsp;
  override <span style="color: #0033ff; font-weight: bold;">protected</span> <span style="color: #339966; font-weight: bold;">function</span> showDisplayForInit<span style="color: #000000;">&#40;</span>elapsedTime<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">int</span><span style="color: #000066; font-weight: bold;">,</span> count<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">int</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Boolean</span> <span style="color: #000000;">&#123;</span>
   <span style="color: #0033ff; font-weight: bold;">return</span> elapsedTime <span style="color: #000066; font-weight: bold;">&gt;</span> <span style="color: #000000; font-weight:bold;">300</span> <span style="color: #000066; font-weight: bold;">&amp;&amp;</span> count == <span style="color: #000000; font-weight:bold;">2</span><span style="color: #000066; font-weight: bold;">;</span>
  <span style="color: #000000;">&#125;</span>
&nbsp;
 <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>Related posts:<ol>
<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>
<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/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/06/flex-spark-preloader-disappear/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Flash/Flex 移动端开发 之 Flex就绪核心组件</title>
		<link>http://blog.richmediaplus.com/2011/06/flash-flex-mobile-dev-ready-components/</link>
		<comments>http://blog.richmediaplus.com/2011/06/flash-flex-mobile-dev-ready-components/#comments</comments>
		<pubDate>Fri, 17 Jun 2011 09:51:41 +0000</pubDate>
		<dc:creator>Alvin / Aedis.Ju</dc:creator>
				<category><![CDATA[Flash/Flex Mobile Dev]]></category>
		<category><![CDATA[Mobile Dev]]></category>
		<category><![CDATA[Adobe Flex]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[移动端开发]]></category>

		<guid isPermaLink="false">http://blog.richmediaplus.com/?p=784</guid>
		<description><![CDATA[Flex控件一向是Adobe代码规范的典型之作。 Flex SDK 4.5之后本身在现有组件和外观进行了代码优化，而且新的移动端就绪组件多出来不少，若直接用ActionScript工程的同学，大可以参考Adobe写的代码，可以避免很多弯路还有能更加快速的学习。 Flex就绪核心组件 控件 Components BusyIndicator（新增组件） Button（新的移动主题） ButtonBar（新的移动主题） CheckBox（新的移动主题） HSlider（新的移动主题） Image（还支持 BitmapImage） Label（新的移动主题） List（支持触摸滚动，含滚动指示符，若移动工程，默认开启） RadioButton/RadioButtonGroup（新的移动主题） TextArea（新的移动主题） TextInput（新的移动主题） 排版 Layout BusyIndicator（新增组件） DataGroup Group HGroup Scroller（支持触摸滚动，含滚动指示符，若移动工程，默认开启） Spacer TileGroup VGroup 视图 Charts 全部all 标准移动应用程序结构 View 基本移动UI容器，每个视图都可以是个View。 actionBarVisible可以设置View上方的标准标题组件是否可见。 和tabBarVisible可以设置下方TAB按钮组件是否可见。 ActionBar 位于View上方的标准标题组件 ViewMenu 从下方弹出的标准菜单组件 ViewNavigator 基于堆栈的历史记录机制管理应用程序中的 ActionBar 和 View 集 为了节省内存消耗，ViewNavigator 在默认情况下将确保任何给定时刻内存中只有一个视图。但它会将之前视图的数据保留在已丢弃的堆栈中，以便用户返回之前的视图时，可使用合适的数据重新将它实例化。 ViewNavigatorApplication 同ViewNavigator，只是更加高级版本的应用程序类，默认支持硬件操作的后退功能。 还提供一种当应用程序退出时保留应用程序视图状态和数据的方式，这样当应用程序下一次启动时，它可以使用相同的当前视图和视图历史记录恢复自己。 TabbedViewNavigator TabbedViewNavigator 类是管理视图导航器容器集合的容器。一次仅一个视图导航器处于活动状态并可见。 [...]
Related posts:<ol>
<li><a href='http://blog.richmediaplus.com/2011/06/flash-flex-mobile-dev-background/' rel='bookmark' title='Flash/Flex 移动端开发 之 现状'>Flash/Flex 移动端开发 之 现状</a></li>
<li><a href='http://blog.richmediaplus.com/2011/09/flash-flex-mobile-dev-dpi/' rel='bookmark' title='Flash/Flex 移动端开发 之 DPI'>Flash/Flex 移动端开发 之 DPI</a></li>
<li><a href='http://blog.richmediaplus.com/2009/07/seo-for-flex-flash/' rel='bookmark' title='SEO For Flex/Flash'>SEO For Flex/Flash</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>Flex控件一向是Adobe代码规范的典型之作。<br />
Flex SDK 4.5之后本身在现有组件和外观进行了代码优化，而且新的移动端就绪组件多出来不少，若直接用ActionScript工程的同学，大可以参考Adobe写的代码，可以避免很多弯路还有能更加快速的学习。</p>
<h2>Flex就绪核心组件</h2>
<h3>控件 Components</h3>
<ul>
<li>BusyIndicator（新增组件）</li>
<li>Button（新的移动主题）</li>
<li>ButtonBar（新的移动主题）</li>
<li>CheckBox（新的移动主题）</li>
<li>HSlider（新的移动主题）</li>
<li>Image（还支持 BitmapImage）</li>
<li>Label（新的移动主题）</li>
<li>List（支持触摸滚动，含滚动指示符，若移动工程，默认开启）</li>
<li>RadioButton/RadioButtonGroup（新的移动主题）</li>
<li>TextArea（新的移动主题）</li>
<li>TextInput（新的移动主题）</li>
</ul>
<h3>排版 Layout</h3>
<ul>
<li>BusyIndicator（新增组件）</li>
<li>DataGroup</li>
<li>Group</li>
<li>HGroup</li>
<li>Scroller（支持触摸滚动，含滚动指示符，若移动工程，默认开启）</li>
<li>Spacer</li>
<li>TileGroup</li>
<li>VGroup</li>
</ul>
<h3>视图 Charts</h3>
<ul>
<li>全部all</li>
</ul>
<h3>标准移动应用程序结构</h3>
<ul>
<li>View<br />
基本移动UI容器，每个视图都可以是个View。<br />
actionBarVisible可以设置View上方的标准标题组件是否可见。<br />
和tabBarVisible可以设置下方TAB按钮组件是否可见。
</li>
<li>ActionBar<br />
位于View上方的标准标题组件
</li>
<li>ViewMenu<br />
从下方弹出的标准菜单组件
</li>
<li>ViewNavigator<br />
基于堆栈的历史记录机制管理应用程序中的 ActionBar 和 View 集<br />
为了节省内存消耗，ViewNavigator 在默认情况下将确保任何给定时刻内存中只有一个视图。但它会将之前视图的数据保留在已丢弃的堆栈中，以便用户返回之前的视图时，可使用合适的数据重新将它实例化。
</li>
<li>ViewNavigatorApplication<br />
同ViewNavigator，只是更加高级版本的应用程序类，默认支持硬件操作的后退功能。<br />
还提供一种当应用程序退出时保留应用程序视图状态和数据的方式，这样当应用程序下一次启动时，它可以使用相同的当前视图和视图历史记录恢复自己。
</li>
<li>TabbedViewNavigator<br />
TabbedViewNavigator 类是管理视图导航器容器集合的容器。一次仅一个视图导航器处于活动状态并可见。
</li>
<li>TabbedViewNavigatorApplication<br />
同TabbedViewNavigator，TabbedViewNavigator 类是管理视图导航器容器集合的应用程序。
</li>
</ul>
<p>Related posts:<ol>
<li><a href='http://blog.richmediaplus.com/2011/06/flash-flex-mobile-dev-background/' rel='bookmark' title='Flash/Flex 移动端开发 之 现状'>Flash/Flex 移动端开发 之 现状</a></li>
<li><a href='http://blog.richmediaplus.com/2011/09/flash-flex-mobile-dev-dpi/' rel='bookmark' title='Flash/Flex 移动端开发 之 DPI'>Flash/Flex 移动端开发 之 DPI</a></li>
<li><a href='http://blog.richmediaplus.com/2009/07/seo-for-flex-flash/' rel='bookmark' title='SEO For Flex/Flash'>SEO For Flex/Flash</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://blog.richmediaplus.com/2011/06/flash-flex-mobile-dev-ready-components/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

