<?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>SILK ROUTE &#187; as3.0</title>
	<atom:link href="http://www.silkrt.com/v01/tag/as30/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.silkrt.com/v01</link>
	<description>W.E. Linked</description>
	<lastBuildDate>Sat, 28 Jan 2012 00:36:41 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>AS3筆記-純MVC心得</title>
		<link>http://www.silkrt.com/v01/2009/07/05/pure-mvc-%e5%bf%83%e5%be%97/</link>
		<comments>http://www.silkrt.com/v01/2009/07/05/pure-mvc-%e5%bf%83%e5%be%97/#comments</comments>
		<pubDate>Mon, 06 Jul 2009 03:33:43 +0000</pubDate>
		<dc:creator>Marc</dc:creator>
				<category><![CDATA[flash]]></category>
		<category><![CDATA[medium]]></category>
		<category><![CDATA[small]]></category>
		<category><![CDATA[as3.0]]></category>

		<guid isPermaLink="false">http://www.silkrt.com/v01/?p=2466</guid>
		<description><![CDATA[人生如戲,戲如人生,要玩遊戲就要有遊戲規則.制定輸贏的基準(要錢,要名,要爽?),而如何贏這個遊戲,就要看怎麼用這些規則玩這個遊戲了~
廢話不多說,OOP(物件導向)也是一堆規則堆成的一種語法,用這些規則可以達到你想要叫電腦做的事, 但並不代表用了規則就做的漂亮.
在OOP規則的世界, 輸贏可以有很多方面, 基本上是如何拼奏這些規則, 達到
1. 讓共同開發的人都能互相了解,分工合作
2. 可以重複使用又易於修改
以上兩樣基準, 由不同的狀況用途, 經過邏輯的推演歸納, 會產生某些特別拼湊的OOP規則,就成了所謂的 Design Pattern了.
Design Pattern 的用意是在解決問題, MVC是眾多 Design Patterns 的一種, 目的在解決的問題就是避免 Model / View 之間偶合的情形.並且利用一些 interface 的寫法讓 開發者之間可以互相了解.
一般flash presentation 網站對Model幾乎只讀取而不改變的情形,所以很自然的就會把 Controller 跟 Model 寫在一起.不過卻會造成 Model 更改不易的情形.
之前在 Flash Coder New York (FCNY) 的 email 討論裡面, 有一堆人提到 MVC 是如何的複雜無用, 其實沒錯, MVC 確實讓人在寫 code 上多了很多程序, 不過這些程序主要也是為了減少 model / view 的耦合現象, [...]]]></description>
			<content:encoded><![CDATA[<p>人生如戲,戲如人生,要玩遊戲就要有<strong>遊戲規則</strong>.制定輸贏的<strong>基準</strong>(要錢,要名,要爽?),而如何贏這個遊戲,就要看<strong>怎麼用這些規則</strong>玩這個遊戲了~</p>
<p>廢話不多說,OOP(物件導向)也是一堆規則堆成的一種語法,用這些規則可以達到你想要叫電腦做的事, 但並不代表用了規則就做的漂亮.</p>
<p>在OOP規則的世界, 輸贏可以有很多方面, 基本上是如何拼奏這些規則, 達到</p>
<p>1. 讓共同開發的人都能互相了解,分工合作</p>
<p>2. 可以重複使用又易於修改</p>
<p>以上兩樣基準, 由不同的狀況用途, 經過邏輯的推演歸納, 會產生某些特別拼湊的OOP規則,就成了所謂的 Design Pattern了.</p>
<p>Design Pattern 的用意是在解決問題, MVC是眾多 Design Patterns 的一種, 目的在解決的問題就是避免 Model / View 之間偶合的情形.並且利用一些 interface 的寫法讓 開發者之間可以互相了解.</p>
<p>一般flash presentation 網站對Model幾乎只讀取而不改變的情形,所以很自然的就會把 Controller 跟 Model 寫在一起.不過卻會造成 Model 更改不易的情形.</p>
<p>之前在 Flash Coder New York (FCNY) 的 email 討論裡面, 有一堆人提到 MVC 是如何的複雜無用, 其實沒錯, MVC 確實讓人在寫 code 上多了很多程序, 不過這些程序主要也是為了減少 model / view 的耦合現象, 讓開發過後的元件可以<strong>重複使用</strong>, that&#8217;s all AS3 OOP programing about.不然直接寫再 Flash IDE 的 Frame 上面就好, 何必還要寫一堆 as.</p>
<p>之前看了一陣子 <a href="http://www.puremvc.org/">PureMVC</a> framework. 覺得好像很複雜, 很多次看一下就放棄了, 這次我選擇不看, 我<strong>直接用</strong>, 發現其實並不難, 而且讓整個開發變得很清楚明瞭.(但是還是要多寫很多Code&#8230;)</p>
<p><img src="http://flashtuts.s3.amazonaws.com/026_PureMVC/assets/images/2.jpg" alt="" width="600" height="450" /></p>
<p>以上是 pureMVC 的官方架構示意圖,看起很嚇人,已經到了有 <a href="http://www.visualcomplexity.com/vc/">infovis</a> 美感的地步.</p>
<p><span id="more-2466"></span>以下是我<span style="color: #ff00ff;"><strong>只管使用面</strong></span>的簡單版</p>
<p><img src="http://farm3.static.flickr.com/2430/3693026910_da6a8b700b_o.jpg" alt="" width="849" height="701" /></p>
<p>PureMVC 的內部架構用了不少很厲害的 patterns, 想要看懂並不容易, 所以不要去管他的架構. 用了就懂了. 以下是一些心得</p>
<p>1. M(proxy), V(mediator), C(command) 都要照他的用法 extends + implements 該元件的相關 classes.</p>
<p style="padding-left: 30px;">M -&gt; extends Proxy implements IProxy</p>
<p style="padding-left: 30px;">V -&gt; extends Mediator implements IMediator</p>
<p style="padding-left: 30px;">C -&gt; extends SimpleCommand implements ICommand (microCommand 我還不知道是幹嘛用的)</p>
<p style="padding-left: 30px;">以上都需要命名</p>
<p>2. Mediator + Proxy:</p>
<p style="padding-left: 30px;">以上MV者都只是個 framework 的溝通管道, 就像拼圖裡面凹凹凸凸的連結部份, 你可以在裡面輕鬆的包個你想要的物件, 這個做法主要是不管你之前的 M/V 用什麼怪寫法或怪名字, 用這個包起來之後就<span style="color: #ff00ff;">可以跟其他的元件接軌</span></p>
<p>3. Command</p>
<p style="padding-left: 30px;">3.1.與 Notification 配對執行.<br />
3.2.經由 retriveProxy / retriveMediator 用名字的字串, 取得 Mediator / Proxy, 可裡面的 method, 並且溝通兩者, 所以 <span style="color: #ff00ff;">M(Proxy),V(Mediator) 不會直接溝通</span></p>
<p>4. Notification</p>
<p style="padding-left: 30px;">用來執行 Command,  Command, Notification 這兩者容易讓人搞混,基本上 Command 是 class, 裡面有 execute, 用來執行一些任務, Notification 則只是一個字串, 像是指令一樣會去執行 Command<br />
<strong>這兩者分開的好處是可以讓不同的 Notification 可以執行相同的 Command.</strong><br />
<span style="color: #ff00ff;"><strong>很多案例都是把 Notification 定義放在 Application Facade 裡面, 我則認為有分開的 Class 用 const 管理這些字串比較好.</strong></span></p>
<p>5. 發送 Notification</p>
<p style="padding-left: 30px;">Proxy, Mediator, Command 都可以發送 sendNotification(Notification字串, <strong>跟隨發送的資訊物件</strong>);</p>
<p>6. 反應 Notification (這是最重要的部份)<br />
執行指令的方法有兩種:</p>
<p style="padding-left: 30px;"><span style="color: #ff00ff;">6.1.Notification -&gt; registerCommand -&gt; Command.execute();</span><br />
在 Application facade, initialize 的時候:<br />
registerCommand(Notification, CommandClass); // Notification字串與 CommandClass 的配對</p>
<p style="padding-left: 30px;"><span style="color: #ff00ff;">6.2.Notification -&gt; listNotificationInterests -&gt; handleNotification(notification:INotification)</span><br />
在Mediator 裡面:<br />
透過 framework 的寫法 extends+implements, 會有一個 override method 要去填: listNotificationInterests, 回傳Notification 字串陣列<br />
如果有以上陣列被執行的話,handleNotification 會被執行</p>
<p>以下是狀況演練<span style="font-size: x-large;"> </span></p>
<p><span style="color: #ff00ff;"><span style="font-size: x-large;"><strong>View 觸發事件</strong></span></span></p>
<p>1.interface event 不改變 model ( 或是 view 自己解決就可以）</p>
<p><img src="http://farm4.static.flickr.com/3660/3692763545_f412633192_o.jpg" alt="" width="849" height="701" /></p>
<p>2.interface event 直接改變 model + view,由 command 發出 notification (state 改變, 像是 sound on / off 之類的, model 不需要load 東西)</p>
<p><img src="http://farm3.static.flickr.com/2518/3693411812_d2cdcf390b_o.jpg" alt="" width="849" height="701" /></p>
<p>3.interface event 改變 Model 但是不發出 notification <span style="color: #ff00ff;">由 Command.retriveMediator 呼叫 Mediator 裡面的 function 更改 view, (比較複雜的改變)<br />
</span></p>
<p><img src="http://farm4.static.flickr.com/3580/3692635391_7a98172ca2_o.jpg" alt="" width="849" height="701" /></p>
<p>4.interface event 改變 Model (load 一些東西） 之後又改變 View. 可以想像 load data 進來的過程,view 要等待 model 讀完才能繼續進行</p>
<p><img src="http://farm4.static.flickr.com/3572/3692455417_9b9d288fb7_o.jpg" alt="" width="849" height="701" /></p>
<p><span style="font-size: x-large;"><span style="color: #ff00ff;"><br />
</span></span></p>
<p><strong><span style="font-size: x-large;"><span style="color: #ff00ff;">Model 改變</span></span></strong></p>
<p>1.Model 更新改變 view (假想讀取預設的 user 內定值改變 view / DeepLinking)</p>
<p><img src="http://farm3.static.flickr.com/2487/3692471401_5541a9e969_o.jpg" alt="" width="849" height="701" /></p>
<p>2.interface event without changing model （像是 menu 開關等等, 視覺上面無傷大雅的改變, 盡量少用, 最好把 state 都還是存在 model 裡面）</p>
<p><img src="http://farm4.static.flickr.com/3606/3693285308_a1434a382e_o.jpg" alt="" width="849" height="701" /></p>
<p>由以上的演練可以得知,</p>
<p style="padding-left: 30px;"><strong>Notification -&gt; Command<br />
這類大概都是會牽扯到 Model 的</strong></p>
<p style="padding-left: 30px;"><strong>Notification -&gt; Mediator.listNotificationInterests<br />
這類就是只去更改 View</strong></p>
<p>Notification 規範的越有系統越好, 尤其不要搞混以上兩者</p>
<p>所以像是 view 4 範例, 可以分成 UPDATE_MODEL,之後要改變 View （步驟 7 sendNotification )之後 change view 的過程可以共用另一個 Notification (UPDATE_VIEW)去呼叫, 這樣的話舊可以共用 Notification 而不會寫了一堆.</p>
<p>可以由的控制方式分作:</p>
<p>多重控制的 view</p>
<p style="padding-left: 30px;">(由多個source 去控制一個 view, source 可能是其他的 view or model）所有元件透過同一個 notification 更新 view</p>
<p>單一控制的 view</p>
<p style="padding-left: 30px;">(一對一的控制, 像是由 scroll bar 控制內容）這種情形可以就直接不用任何 notification 直接 view 裡面解決就可以</p>
<p>改變 model 的 view update.</p>
<p style="padding-left: 30px;">這種情形最好繞到 model, 由 model(proxy) 透過 sendNotification 去更改 view. 這樣一來 控制端的 view 跟  model 都可以利用同一個 notification 去更改被多元控制的 view</p>
<p>由用途可以分作</p>
<p>System</p>
<p>GUI (Graphic User Interface)</p>
<p>View</p>
<p>PS:<br />
這篇不錯 : <a href="http://flash.tutsplus.com/tutorials/workflow/understanding-the-puremvc-open-source-framework/">http://flash.tutsplus.com/tutorials/workflow/understanding-the-puremvc-open-source-framework/</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.silkrt.com/v01/2009/07/05/pure-mvc-%e5%bf%83%e5%be%97/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>AS3筆記-Array的異次元空間</title>
		<link>http://www.silkrt.com/v01/2009/06/16/as3%e7%ad%86%e8%a8%98-array%e7%9a%84%e7%95%b0%e6%ac%a1%e5%85%83%e7%a9%ba%e9%96%93/</link>
		<comments>http://www.silkrt.com/v01/2009/06/16/as3%e7%ad%86%e8%a8%98-array%e7%9a%84%e7%95%b0%e6%ac%a1%e5%85%83%e7%a9%ba%e9%96%93/#comments</comments>
		<pubDate>Tue, 16 Jun 2009 18:55:00 +0000</pubDate>
		<dc:creator>Marc</dc:creator>
				<category><![CDATA[small]]></category>
		<category><![CDATA[as3.0]]></category>

		<guid isPermaLink="false">http://www.silkrt.com/v01/2009/06/16/as3%e7%ad%86%e8%a8%98-array%e7%9a%84%e7%95%b0%e6%ac%a1%e5%85%83%e7%a9%ba%e9%96%93/</guid>
		<description><![CDATA[
var a:Array = new Array();
var b:Sprite = new Sprite();
var c:Sprite = new MovieClip();
b.name = &#34;myName&#34;;
c.name = &#34;myName2&#34;;
a[b.name]=b;
a.myName2=c;
a.push(&#34;cool&#34;);
trace(&#34;a[0]=&#34;,a[0]);
trace(&#34;a.length=&#34;,a.length);
trace(&#34;for in loop&#34;);
trace(a.myName,a1);
for (var i:* in a) {
	trace(i,&#34;=&#34;,a[i]);
}

array[數字] -> 會進到 array 裡面,並且會count length
array[字串] -> array.字串 -> 會變成 array 的 property, 像是object 一樣 (public dynamic class Array extends Object), 這樣做並不會 count length
]]></description>
			<content:encoded><![CDATA[<pre class="brush: as3; title: ; notranslate">
var a:Array = new Array();
var b:Sprite = new Sprite();
var c:Sprite = new MovieClip();
b.name = &quot;myName&quot;;
c.name = &quot;myName2&quot;;
a[b.name]=b;
a.myName2=c;
a.push(&quot;cool&quot;);
trace(&quot;a[0]=&quot;,a[0]);
trace(&quot;a.length=&quot;,a.length);
trace(&quot;for in loop&quot;);
trace(a.myName,a1);
for (var i:* in a) {
	trace(i,&quot;=&quot;,a[i]);
}
</pre>
<p>array[數字] -> 會進到 array 裡面,並且會count length<br />
array[字串] -> array.字串 -> 會變成 array 的 property, 像是object 一樣 (public dynamic class Array extends Object), 這樣做並不會 count length</p>
]]></content:encoded>
			<wfw:commentRss>http://www.silkrt.com/v01/2009/06/16/as3%e7%ad%86%e8%a8%98-array%e7%9a%84%e7%95%b0%e6%ac%a1%e5%85%83%e7%a9%ba%e9%96%93/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>AS3筆記-Polymorphism</title>
		<link>http://www.silkrt.com/v01/2009/05/12/as3%e7%ad%86%e8%a8%98-polymorphism/</link>
		<comments>http://www.silkrt.com/v01/2009/05/12/as3%e7%ad%86%e8%a8%98-polymorphism/#comments</comments>
		<pubDate>Tue, 12 May 2009 18:21:00 +0000</pubDate>
		<dc:creator>Marc</dc:creator>
				<category><![CDATA[flash]]></category>
		<category><![CDATA[medium]]></category>
		<category><![CDATA[as3.0]]></category>
		<category><![CDATA[oop]]></category>

		<guid isPermaLink="false">http://www.silkrt.com/v01/?p=2070</guid>
		<description><![CDATA[多態 Polymorphism 是OOP物件導向程式三惡霸之一. 懂的人可能還不知道要怎麼運用,不懂的人可以看看這篇專為as3製作網頁而寫的簡易了解版.
假設今天A君被layoff,要做一個portfolio找工作, 想用 about,  website, contact為簡單明瞭秀三個頁面,

about, 裡面是一些自我瞎掰介紹
works, 跟別人的合作案跟借來的作品
contact, 將要搬家的地址跟快要丟掉的手機電話

很快的規劃,以最精簡的方式可以有以下幾個 classes 的製作 (如果連這都想不出來,還是趕快準備打包吧!)


Main.as, document class &#8211; 聽 Menu 的事件 切換內容
Menu.as, menu class &#8211; 用 TextFiled 建立出一些 Menu
About.as, 裝 about 這頁的內容
Works.as, 裝作品, slideshow?
Contact.as, 放聯絡資訊, form?

在按 Menu 切換內容的時候,要移除上一個內容,所以在 About.as, Works.as,  Contact.as 裡面都有一個自己的 remove function, 把自己移除.
Main.as會像以下這樣

//properties
private var aboutContent:About;
private var worksContent:Works;
private var contactContent:Contact;
//methods
private function changeContent(evt:MouseEvent):void{
//偵測有沒有這個物件,有的話再移除
if(aboutContent){
aboutContent.remove();
}
if(worksContent){
worksContent.remove();
}
if(contactContent){
contactContent.remove();
}
//偵測是哪個menu被按到,然後去 new 內容
var contentName:String [...]]]></description>
			<content:encoded><![CDATA[<p>多態 <a class="mw-redirect" title="Polymorphism (computer science)" href="http://en.wikipedia.org/wiki/Polymorphism_%28computer_science%29">Polymorphism</a> 是OOP物件導向程式三惡霸之一. 懂的人可能還不知道要怎麼運用,不懂的人可以看看這篇專為as3製作網頁而寫的簡易了解版.</p>
<p>假設今天A君被layoff,要做一個portfolio找工作, 想用 about,  website, contact為簡單明瞭秀三個頁面,</p>
<ul>
<li>about, 裡面是一些自我瞎掰介紹</li>
<li>works, 跟別人的合作案跟借來的作品</li>
<li>contact, 將要搬家的地址跟快要丟掉的手機電話</li>
</ul>
<p>很快的規劃,以最精簡的方式可以有以下幾個 classes 的製作 (如果連這都想不出來,還是趕快準備打包吧!)</p>
<p><span id="more-2070"></span></p>
<ul>
<li>Main.as, document class &#8211; 聽 Menu 的事件 切換內容</li>
<li>Menu.as, menu class &#8211; 用 TextFiled 建立出一些 Menu</li>
<li>About.as, 裝 about 這頁的內容</li>
<li>Works.as, 裝作品, slideshow?</li>
<li>Contact.as, 放聯絡資訊, form?</li>
</ul>
<p>在按 Menu 切換內容的時候,要移除上一個內容,所以在 About.as, Works.as,  Contact.as 裡面都有一個自己的 remove function, 把自己移除.</p>
<p>Main.as會像以下這樣</p>
<pre class="brush: as3; title: ; notranslate">
//properties
private var aboutContent:About;
private var worksContent:Works;
private var contactContent:Contact;
//methods
private function changeContent(evt:MouseEvent):void{
//偵測有沒有這個物件,有的話再移除
if(aboutContent){
aboutContent.remove();
}
if(worksContent){
worksContent.remove();
}
if(contactContent){
contactContent.remove();
}
//偵測是哪個menu被按到,然後去 new 內容
var contentName:String = evt.target.text;
switch(contentName){
case &quot;about&quot;:
aboutContent  = new About();
aboutContent.x=100;
addChild(aboutContent);
break;
case &quot;works&quot;:
worksContent = new Works();
worksContent.x=100;
addChild(worksContent);
break;
case &quot;contact&quot;:
contactContet = new Contact();
contactContent.x=100;
addChild(contactContent);
break;
default:
break;
}
}
</pre>
<p>以上如果有耐心看完,那妳/你就快了解一半了,恭喜</p>
<p>如果妳/你發現:</p>
<pre class="brush: as3; title: ; notranslate">if(aboutContent){
aboutContent.remove();
}
if(worksContent){
worksContent.remove();
}
if(contactContent){
contactContent.remove();
}</pre>
<p>要寫三次,很鳥,那恭喜妳/你,妳/你的code會越寫越漂亮.</p>
<p>沒錯! 這裡就是要用到 polymorphism 的地方:</p>
<p>目標是要怎麼達成</p>
<pre class="brush: as3; title: ; notranslate">if(content){
content.remove();
}</pre>
<p>呢? 那就要靠 super or interface 了</p>
<p>可以用</p>
<pre class="brush: as3; title: ; notranslate">public interface IContent{
function remove():void;
}</pre>
<p>or</p>
<pre class="brush: as3; title: ; notranslate">public class AbstractContent{
public function remove():void{
throw Error(&quot;abstract function must be override&quot;); // 提醒一定要被改寫
}</pre>
<p>之後用 About.as, Works.as, Contact.as 去 implements IContent or extends AbstractContent 之後<br />
以用 IContent 為例, in Main.as:</p>
<pre class="brush: as3; title: ; notranslate">
//type 定義的時候因為 implements 的關係可以全部用父類別
private var content:AbstractContent;
private function changeContent(evt:MouseEvent):void{
if(content){ //偵測有沒有這個物件,有的話再移除
content.remove();
}
var contentName:String = evt.target.text;
switch(contentName){
case &quot;about&quot;:
content= new About();
//如果要去呼叫 About type裡面的 method 的時候,可以把他的Ｔｙｐｅ轉回來
About(content).doOtherStuff();
break;
case &quot;works&quot;:
content= new Works();
break;
case &quot;contact&quot;:
content= new Contact();
break;
default:
break;
}
//這裡還可以統一設定
content.x = 100;
addChild(content);
}
</pre>
<p>類似以上這樣.</p>
<p>總之,這有點像是以前學代數乘法,<br />
(a*b+a*c+a*d)*k = a*(b+c+d)*k<br />
共同的部分可以提出來,<br />
共同重複的class也是,可以寫成interface / super class 並以這個為 type. 就可以用 polymorphism去在 runtime 執行共同擁有的部分.</p>
<p>因為型態是屬於父類別,而卻還是有自己型態(type)裡面的properties / methods,這樣寫就可以相互轉換了,所以叫做多形(or多态)</p>
<p>這樣有比較容易一點嗎?<br />
<a href="http://www.silkrt.com/v01/wp-content/uploads/2009/05/polymorphismdemo1.zip">如果還沒有,示範都好了(.zip)</a></p>
<p>此外,我不確定這跟多形有沒有關係,就是很基本的type轉換,讓FDT開心,也讓自己容易了解.<br />
如果你將物件從DisplayObjectContainer裡面抓出來</p>
<pre class="brush: as3; title: ; notranslate">
for(var i=0;i&lt;10;i++){
var menu:MenuItem = new MenuItem();
addChild(menu); }
//之後想要呼叫menu裡面的method: setLabel.
this.getChildAt(3).setLabel(&quot;songYY&quot;);
//該死的DisplayObjectContainer.getChildAt是回傳Object,Object物件裡面怎麼可能會有setLabel呢? 所以你的 setLabel 在 FDT 裡面會找不到... 這時候你可以寫:
MenuItem(this.getChildAt(3)).setLabel(&quot;songYY&quot;);
//去轉換type就OK了
</pre>
<p>還有用在Event.target回傳的時候也很好用:</p>
<pre class="brush: as3; title: ; notranslate">
private function handleClick(evt:MouseEvent):void{
evt.target.setLabel(&quot;Clicked&quot;);
//evt.target:Object ,裡面不會有 setActivateState();
//可以加上type解決.
MenuItem(evt.target).setLabel(&quot;Clicked&quot;);
}
</pre>
<p>PS: Object 是dynamic Class,所以以上不轉換成 MenuItem並不一定會錯,只是FDT會給你警告,很討厭,<br />
而且個人覺得有良好的typing轉換習慣是會讓別人看的了解,自己也會進步的.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.silkrt.com/v01/2009/05/12/as3%e7%ad%86%e8%a8%98-polymorphism/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>AS3筆記-Class Path</title>
		<link>http://www.silkrt.com/v01/2009/04/08/as3%e7%ad%86%e8%a8%98-class-path/</link>
		<comments>http://www.silkrt.com/v01/2009/04/08/as3%e7%ad%86%e8%a8%98-class-path/#comments</comments>
		<pubDate>Wed, 08 Apr 2009 18:34:07 +0000</pubDate>
		<dc:creator>Marc</dc:creator>
				<category><![CDATA[flash]]></category>
		<category><![CDATA[medium]]></category>
		<category><![CDATA[as3.0]]></category>

		<guid isPermaLink="false">http://www.silkrt.com/v01/?p=1862</guid>
		<description><![CDATA[許多人用 flash, 用到現在,可能還是對 class path 的設定不是很了解, 尤其在面對使用 3rd party editor 跟 Flash IDE + FDT 的時候,常常發生觀念不清楚的錯亂情形.
其實原則很簡單,就是要了解兩邊的規則,讓 Editor 以及 Compiler 能找到的 class path是一樣的,就不會出問題了.

Flash IDE 的規則 :
為了特定的單獨案子設定
在Publish setting &#62;Flash&#62;Actionscript 3.0 &#62; Setting&#8230;
常設:每次new案子都會有這個設定
在Edit &#62; preferecne&#62;Actionscript&#62;Actionscript 3.0 裡面設定


方便起見在與 .fla 檔案同一層的 folder　自動就會是內定的 classpath,如果你的 fla沒有跟 src 放在一起,那就要把那些 path 加進來
內建core library(多案共用部分): $(AppConfig)/ActionScript 3.0/Classes -&#62; &#8220;$(AppConfig)&#8221; stands for &#8220;C:\Program Files\Adobe\Adobe Flash CS3\en\Configuration&#8221;
Flash IDE [...]]]></description>
			<content:encoded><![CDATA[<p>許多人用 flash, 用到現在,可能還是對 class path 的設定不是很了解, 尤其在面對使用 3rd party editor 跟 Flash IDE + FDT 的時候,常常發生觀念不清楚的錯亂情形.</p>
<p>其實原則很簡單,就是要了解兩邊的規則,讓 Editor 以及 Compiler 能找到的 class path是一樣的,就不會出問題了.</p>
<p><span id="more-1862"></span></p>
<p><span style="color: #ff00ff;"><strong>Flash IDE 的規則 </strong>:</span></p>
<p>為了特定的單獨案子設定<br />
在Publish setting &gt;Flash&gt;Actionscript 3.0 &gt; Setting&#8230;</p>
<p><strong>常設:每次new案子都會有這個設定</strong><br />
在Edit &gt; preferecne&gt;Actionscript&gt;Actionscript 3.0 裡面設定</p>
<p><strong></strong><strong><a href="http://www.silkrt.com/v01/wp-content/uploads/2009/04/classpath.gif"><img class="alignnone size-full wp-image-1865" title="classpath" src="http://www.silkrt.com/v01/wp-content/uploads/2009/04/classpath.gif" alt="classpath" width="600" height="735" /></a></strong></p>
<ul>
<li>方便起見在與 .fla 檔案同一層的 folder　自動就會是內定的 classpath,如果你的 fla沒有跟 src 放在一起,那就要把那些 path 加進來</li>
<li>內建core library(多案共用部分): $(AppConfig)/ActionScript 3.0/Classes -&gt; &#8220;$(AppConfig)&#8221; stands for &#8220;C:\Program Files\Adobe\Adobe Flash CS3\en\Configuration&#8221;</li>
<li>Flash IDE 會自動找到 Component 需要用到的 classpath (多案共用部分)</li>
<li>Flash IDE 裡面在撰寫 code 的時候,compiler會自動去找 class path,不需要自己寫 import &#8230;.</li>
</ul>
<p><span style="color: #ff00ff;"><strong>FDT / 3rd Party Editor 的規則 </strong>:</span><br />
以FDT為例: windows&gt;prefereces&gt;FDT&gt;CoreLibraries&gt;AS3 Core Libraries(tab),( 我覺得FDT的設定相當的令人頭暈),由這種方式加進來的 Linked Lib 在 icon 上面會有一個小箭頭.</p>
<ul>
<li>Linked Lib (src/folder,多案共用部分)<br />
在 FDT 裡面, 要先透過介面去把 Path 設定成好記憶的  &#8220;Path Variable&#8221;  並且給他名字. 這個 path 可以指到 .swc 檔(壓縮/pre-compiled過的classes)或是class folder.<br />
你可以找一次先把所有會用到的 class path 找到,紛紛設定成 variable, 之後在每個案子上按右鍵 &gt; New Linked Libraries<a href="http://www.silkrt.com/v01/wp-content/uploads/2009/04/fdt_classpath2.gif"><img class="alignnone size-full wp-image-1863" title="fdt_classpath2" src="http://www.silkrt.com/v01/wp-content/uploads/2009/04/fdt_classpath2.gif" alt="fdt_classpath2" width="450" height="262" /></a></p>
<ul>
<li>swc : 可以將預先設定好的好的 swc path 加進來</li>
<li>folder: 可以將預先設定好的好的 folder path 加進來</li>
</ul>
</li>
<li>Source Folder<a href="http://www.silkrt.com/v01/wp-content/uploads/2009/04/fdt_classpath4.gif"><img class="alignnone size-full wp-image-1864" title="fdt_classpath4" src="http://www.silkrt.com/v01/wp-content/uploads/2009/04/fdt_classpath4.gif" alt="fdt_classpath4" width="450" height="262" /></a><br />
Source Folder 是用在針對每個案子自行開發的部分,由於他沒有像 flash IDE 一樣會根據 .fla 的所在位置自動設定成 classpath, 所以如果用 Flash IDE Compile swf,要記得把相對的 .fla 所在地的path設定上去(在 folder 上面按右鍵,如圖)</li>
<li>就算加上了 class path,在FDT裡面撰寫 as3的時候還是得將所有有用到的 classes import 來告訴 FDT 編輯器的realtime code hinting/debug 去找相關的 reference.</li>
<p><strong></strong></ul>
<p><span style="color: #ff00ff;">總結:</span></p>
<p><strong>Compiler 在 compile的時候會根據class path的路徑當作根,開始往下找，所以flash.display.* 其實是在其中一個 class path 裡面的 &#8220;\flash\display&#8221; folder,&#8221;.&#8221;代表folder路徑,而 &#8220;*&#8221; 代表該 folder 底下所有的class.</strong></p>
<p><strong>同一個路徑底下的class我們稱他叫做 package,通常都是一組為了同一個目的寫出來的classes,很多時候我們會用到某package底下的很多class,這時候我們就會用&#8221;.*&#8221;來指定,而不用一個一個class來寫,而使用&#8221;.*&#8221;也不會牽扯到compile後檔案會比較大的問題,因為他只是叫compiler找該路徑底下有用到的class(es)而已.&#8221;.*&#8221;只會找該層目錄底下的class,該層目錄底下的目錄並不會去找.<span style="color: #ff0000;"><br />
</span></strong></p>
<p><span style="color: #ff0000;"><strong>由於一個案子常常會有許多的 linked class path,所以必須要避免路徑跟檔名都一樣的情形,因為這樣compler會不知道要去找哪個class來compile.(好像可以用 name space解決,不過我沒用過)<br />
</strong></span></p>
<p><strong>在flash IDE裡面有很多內建的class path,這些class一定要相對的也在FDT裡面設定(雖然不設定,flash IDE照樣可以compiler,因為compiler是根據flash IDE裡面的設定,不過在FDT裡面會出現一堆紅字.不建議)</strong></p>
<p><strong><span style="color: #ff00ff;">Flash IDE vs FDT editor Match 表:</span><br />
</strong></p>
<table style="border-style: solid; border-width: 1pt;" border="1">
<tbody>
<tr>
<td></td>
<td>Flash IDE</td>
<td>Eclipse FDT</td>
</tr>
<tr>
<td>fla folder</td>
<td>,fla folder</td>
<td>要match</td>
</tr>
<tr>
<td>flash.*<br />
(core)<br />
(playerglobal.swc)</td>
<td>$(AppConfig)/ActionScript 3.0/Classes</td>
<td>C:\Program Files\Adobe\Adobe Flash CS3\en\Configuration(PC)</td>
</tr>
<tr>
<td>custom lib</td>
<td>自定共用library (ex:tweener,papervision)</td>
<td>要match</td>
</tr>
<tr>
<td>fl.*<br />
Flash component<br />
(如果有用到的話)</td>
<td style="border-style: solid; border-width: 1px;">Flash IDE 裡面的 component</td>
<td>fl library,這個放在很多地方,這我不太確定(PC)<br />
<strong>沒有compile的 folders (.as files)</strong><br />
C:\Program Files\Adobe\Adobe Flash CS3\en\Configuration\Component Source\ActionScript 3.0<br />
\FLVPlayback<br />
\FLVPlaybackCaptioning<br />
\User Interface</p>
<p><strong>compiled</strong><br />
C:\Program Files\Adobe\Adobe Flash CS3\en\Configuration\Components</td>
</tr>
<tr>
<td>mx.*<br />
Flex SDK component<br />
(如果有用到的話)</td>
<td>C:\flex_sdk_3\frameworks\projects\framework\src</td>
<td>C:\flex_sdk_3\frameworks\projects\framework\src</td>
</tr>
</tbody>
</table>
<p><span style="font-size: x-small;">(以上有錯請留言更正</span>)</p>
<p>另外一項會令人混淆的地方就是 swf 讀取檔案的位置:</p>
<p>在撰寫 .as 的時候, code裡面如果要 refer / load 外部檔案, 必須要以該compile候的 .swf 為主,如果該 .swf 又被其他的 swf load 進去的話,那要以最後 embed的那個為跟目錄開始向下編寫路徑.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.silkrt.com/v01/2009/04/08/as3%e7%ad%86%e8%a8%98-class-path/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>AS3筆記-啟動流程</title>
		<link>http://www.silkrt.com/v01/2009/03/24/as3%e7%ad%86%e8%a8%98-%e5%95%9f%e5%8b%95%e6%b5%81%e7%a8%8b/</link>
		<comments>http://www.silkrt.com/v01/2009/03/24/as3%e7%ad%86%e8%a8%98-%e5%95%9f%e5%8b%95%e6%b5%81%e7%a8%8b/#comments</comments>
		<pubDate>Tue, 24 Mar 2009 22:47:19 +0000</pubDate>
		<dc:creator>Marc</dc:creator>
				<category><![CDATA[flash]]></category>
		<category><![CDATA[small]]></category>
		<category><![CDATA[as3.0]]></category>

		<guid isPermaLink="false">http://www.silkrt.com/v01/?p=1789</guid>
		<description><![CDATA[相信如果寫程式,都會以能夠共用為目標,這樣不用每次都重寫code, 再寫各式各樣的小tool的時候,不免希望整個team寫法一致,所以寫好的東西大家自然就會使用.
經過一些經驗以後,發現幾乎所有的工具再使用的時候,都會具有下列的幾個動作
1. new -&#62; 2. setting (必要參數,內定參數) -&#62; 3. init -&#62; 4.interact(開始使用互動)
ex:

//1.new
var ss : Slideshow = new Slideshow();
//2.setting
ss.imageFileArray = imgAry;
ss.autoPlay=true;
ss.transitionStyle=&#34;fadeIn&#34;;
//3.init
ss.init();
//4.interact
ss.showSlide(4);

對於slideshow來講,imageFileArray應該是必備的,必須強迫使用者輸入,所以我覺得可以放在constructor強迫人填:
1. new (必要參數) -&#62; 2. setting (內定參數) -&#62; 3. init -&#62; 4.interact(開始使用互動)

//1.new
var ss : Slideshow = new Slideshow(imgAry);
//2.setting
ss.autoPlay=true;
ss.transitionStyle=&#34;fadeIn&#34;;
//3.init
ss.init();
//4.interact
ss.showSlide(4);

補充: 關於 必要參數 / 內定參數是否放在constructor裡面?
function裡面的paramater是有前後之分的,通常必須設定的要放前面,有內建值的放後面.這樣的順序如果要跳著設定會變的比較麻煩.
ex:
public function Slideshow(fileAry:Array, autoplay:Boolean=true, interval:Number=5, startfrom:Number =null)
像是這樣的constructor,如果要只改變 interval的話要這樣寫
var ss:Slideshow = new Slideshow(myArray,true,10);
你要多打個 true,而且還要記得每一個裡面代表的是什麼,別人打開code的時候也比較容易看不懂. 所以我決定只把必要參數放在constructor.
]]></description>
			<content:encoded><![CDATA[<p>相信如果寫程式,都會以能夠共用為目標,這樣不用每次都重寫code, 再寫各式各樣的小tool的時候,不免希望整個team寫法一致,所以寫好的東西大家自然就會使用.</p>
<p>經過一些經驗以後,發現幾乎所有的工具再使用的時候,都會具有下列的幾個動作</p>
<p>1. new -&gt; 2. setting (必要參數,內定參數) -&gt; 3. init -&gt; 4.interact(開始使用互動)</p>
<p>ex:</p>
<pre class="brush: as3; title: ; notranslate">
//1.new
var ss : Slideshow = new Slideshow();
//2.setting
ss.imageFileArray = imgAry;
ss.autoPlay=true;
ss.transitionStyle=&quot;fadeIn&quot;;
//3.init
ss.init();
//4.interact
ss.showSlide(4);
</pre>
<p>對於slideshow來講,imageFileArray應該是必備的,必須強迫使用者輸入,所以我覺得可以放在constructor強迫人填:<br />
1. new (必要參數) -&gt; 2. setting (內定參數) -&gt; 3. init -&gt; 4.interact(開始使用互動)</p>
<pre class="brush: as3; title: ; notranslate">
//1.new
var ss : Slideshow = new Slideshow(imgAry);
//2.setting
ss.autoPlay=true;
ss.transitionStyle=&quot;fadeIn&quot;;
//3.init
ss.init();
//4.interact
ss.showSlide(4);
</pre>
<p>補充: 關於 必要參數 / 內定參數是否放在constructor裡面?</p>
<p>function裡面的paramater是有前後之分的,通常必須設定的要放前面,有內建值的放後面.這樣的順序如果要跳著設定會變的比較麻煩.</p>
<p>ex:<br />
public function Slideshow(fileAry:Array, autoplay:Boolean=true, interval:Number=5, startfrom:Number =null)<br />
像是這樣的constructor,如果要只改變 interval的話要這樣寫<br />
var ss:Slideshow = new Slideshow(myArray,<span style="color: #ff0000;"><strong>true</strong></span>,10);<br />
你要<span style="color: #ff0000;"><strong>多打個 true</strong></span>,而且還要記得每一個裡面代表的是什麼,別人打開code的時候也比較容易看不懂. 所以我決定只把必要參數放在constructor.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.silkrt.com/v01/2009/03/24/as3%e7%ad%86%e8%a8%98-%e5%95%9f%e5%8b%95%e6%b5%81%e7%a8%8b/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>AS3筆記-Number,uint and int</title>
		<link>http://www.silkrt.com/v01/2009/03/09/as3%e7%ad%86%e8%a8%98-numberuint-and-int/</link>
		<comments>http://www.silkrt.com/v01/2009/03/09/as3%e7%ad%86%e8%a8%98-numberuint-and-int/#comments</comments>
		<pubDate>Mon, 09 Mar 2009 18:54:09 +0000</pubDate>
		<dc:creator>Marc</dc:creator>
				<category><![CDATA[flash]]></category>
		<category><![CDATA[small]]></category>
		<category><![CDATA[as3.0]]></category>

		<guid isPermaLink="false">http://www.silkrt.com/v01/?p=1684</guid>
		<description><![CDATA[在AS3裡面,在宣告變數/物件時,需要有自己的類別(type)
在數字方面,除了原有的 Number, AS3比原本的 AS 多了兩種 type: uint (unsigned int) and int.
以下是三者的分別:
NUMBER:  64 bit double-precision
trace(Number.MAX_VALUE,Number.MIN_VALUE);
//1.79769313486231e+308 4.9406564584124654e-324
UINT: 32 bit unsigned integer (沒有正負值)
用於 32 bit 顏色
uint 其值為 32bit 的數字,只有正數
trace(uint.MAX_VALUE,uint.MIN_VALUE);
//4294967295 0
INT: 32 bit integer (有正負值)
用於for loop
int 其值為 32bit 的數字,正負各半(不過要用掉 1bit去紀錄正負值,所以正負直的範圍各只有 31位)
trace(int.MAX_VALUE,int.MIN_VALUE);
//2147483647 -2147483648
]]></description>
			<content:encoded><![CDATA[<p>在AS3裡面,在宣告變數/物件時,需要有自己的類別(type)</p>
<p>在數字方面,除了原有的 Number, AS3比原本的 AS 多了兩種 type: uint (unsigned int) and int.</p>
<p>以下是三者的分別:</p>
<p>NUMBER:  64 bit double-precision<br />
trace(Number.MAX_VALUE,Number.MIN_VALUE);<br />
//1.79769313486231e+308 4.9406564584124654e-324</p>
<p>UINT: 32 bit unsigned integer (沒有正負值)<br />
用於 32 bit 顏色<br />
uint 其值為 32bit 的數字,只有正數<br />
trace(uint.MAX_VALUE,uint.MIN_VALUE);<br />
//4294967295 0</p>
<p>INT: 32 bit integer (有正負值)<br />
用於for loop<br />
int 其值為 32bit 的數字,正負各半(不過要用掉 1bit去紀錄正負值,所以正負直的範圍各只有 31位)<br />
trace(int.MAX_VALUE,int.MIN_VALUE);<br />
//2147483647 -2147483648</p>
]]></content:encoded>
			<wfw:commentRss>http://www.silkrt.com/v01/2009/03/09/as3%e7%ad%86%e8%a8%98-numberuint-and-int/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>AS3筆記-contains</title>
		<link>http://www.silkrt.com/v01/2009/01/28/as3%e7%ad%86%e8%a8%98-contains/</link>
		<comments>http://www.silkrt.com/v01/2009/01/28/as3%e7%ad%86%e8%a8%98-contains/#comments</comments>
		<pubDate>Wed, 28 Jan 2009 16:50:06 +0000</pubDate>
		<dc:creator>Marc</dc:creator>
				<category><![CDATA[flash]]></category>
		<category><![CDATA[small]]></category>
		<category><![CDATA[as3.0]]></category>

		<guid isPermaLink="false">http://www.silkrt.com/v01/?p=1606</guid>
		<description><![CDATA[今天發現contains蠻好用的,這是在偵測某個displayContainer裡面是否擁有某displayObject是Child

var a:Sprite = new Sprite();
trace(this.contains(a)); // false

]]></description>
			<content:encoded><![CDATA[<p>今天發現contains蠻好用的,這是在偵測某個displayContainer裡面是否擁有某displayObject是Child</p>
<pre class="brush: as3; title: ; notranslate">
var a:Sprite = new Sprite();
trace(this.contains(a)); // false
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.silkrt.com/v01/2009/01/28/as3%e7%ad%86%e8%a8%98-contains/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>AS3筆記-give me A break</title>
		<link>http://www.silkrt.com/v01/2009/01/16/as3%e7%ad%86%e8%a8%98-give-me-a-break/</link>
		<comments>http://www.silkrt.com/v01/2009/01/16/as3%e7%ad%86%e8%a8%98-give-me-a-break/#comments</comments>
		<pubDate>Fri, 16 Jan 2009 18:01:04 +0000</pubDate>
		<dc:creator>Marc</dc:creator>
				<category><![CDATA[small]]></category>
		<category><![CDATA[as3.0]]></category>

		<guid isPermaLink="false">http://www.silkrt.com/v01/2009/01/16/as3%e7%ad%86%e8%a8%98-give-me-a-break/</guid>
		<description><![CDATA[不知道大家有沒有遇過用CMS系統GENERATE出來的XML裡面只有一個linebreak但是進了FLASH的TextField render出來變成兩個.
經友人A以及G網查尋,發現:
\n = linux
\r = mac
\r\n = the damned pc linefeed.
所以用PC按的ENTER會有他媽的兩個隱藏字元. 設定進入FLASH後就會有兩倍的LINE BREAK!!
遇到這種怪事可以用相同詭異的regEx把他去除:

var pcLB:RegExp = /\r\n/g;
var macLB:RegExp = /\r/g;
var linuxLB:RegExp = /\n/g;
_text = _text.replace(linuxLB, &#34;\n&#34;);
_text = _text.replace(pcLB, &#34;\n&#34;);
_text = _text.replace(macLB, &#34;\n&#34;);

以上,少西以後解散! Break!
]]></description>
			<content:encoded><![CDATA[<p>不知道大家有沒有遇過用CMS系統GENERATE出來的XML裡面只有一個linebreak但是進了FLASH的TextField render出來變成兩個.<br />
經友人A以及<a href="http://blog.martinlegris.com/?p=71" target="_blank">G網查尋</a>,發現:<br />
\n = linux<br />
\r = mac<br />
\r\n = the damned pc linefeed.</p>
<p>所以用PC按的ENTER會有他媽的兩個隱藏字元. 設定進入FLASH後就會有兩倍的LINE BREAK!!<br />
遇到這種怪事可以用相同詭異的regEx把他去除:</p>
<pre class="brush: as3; title: ; notranslate">
var pcLB:RegExp = /\r\n/g;
var macLB:RegExp = /\r/g;
var linuxLB:RegExp = /\n/g;
_text = _text.replace(linuxLB, &quot;\n&quot;);
_text = _text.replace(pcLB, &quot;\n&quot;);
_text = _text.replace(macLB, &quot;\n&quot;);
</pre>
<p>以上,少西以後解散! Break!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.silkrt.com/v01/2009/01/16/as3%e7%ad%86%e8%a8%98-give-me-a-break/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>AS3筆記-DL+MVC控制心得</title>
		<link>http://www.silkrt.com/v01/2008/11/08/as3%e7%ad%86%e8%a8%98-dlmvc%e6%8e%a7%e5%88%b6%e5%bf%83%e5%be%97/</link>
		<comments>http://www.silkrt.com/v01/2008/11/08/as3%e7%ad%86%e8%a8%98-dlmvc%e6%8e%a7%e5%88%b6%e5%bf%83%e5%be%97/#comments</comments>
		<pubDate>Sat, 08 Nov 2008 07:45:15 +0000</pubDate>
		<dc:creator>Marc</dc:creator>
				<category><![CDATA[concept]]></category>
		<category><![CDATA[flash]]></category>
		<category><![CDATA[large]]></category>
		<category><![CDATA[web]]></category>
		<category><![CDATA[as3.0]]></category>
		<category><![CDATA[design pattern]]></category>
		<category><![CDATA[information architecture]]></category>
		<category><![CDATA[interaction design]]></category>

		<guid isPermaLink="false">http://www.silkrt.com/v01/?p=1198</guid>
		<description><![CDATA[在 Ajax 的強力壓陣下, Flash 在許多功能像是 SEO / Direct Link 方面遠遠比不上傳統直接暴露原始黨讓 browser / robots 讀取的 html 頁面.
許多案子紛紛的靠往 Ajax 網站而捨棄 flash, 為求生存, Flash based website 除了要提供更複雜的設計需求, 還必須要解決本身在 SEO / Diret Link 不如 html 的缺失, 所以就出現了熱門的 DeepLinking (DL) 的機制, 以 SWFAddress 為大宗.
如此一來解決了所有內容包含在 Flash 內的困擾, 讓 URL 上的網址可以對應到相關的 Flash 頁面.
相信有做過 DL 的人都知道, 要完全的雙向 DL, 是寫 AS3 的一大挑戰,除了要儘可能的做到絢麗的互動設計之外,還要兼顧到 DL 的機制, [...]]]></description>
			<content:encoded><![CDATA[<p>在 Ajax 的強力壓陣下, Flash 在許多功能像是 SEO / Direct Link 方面遠遠比不上傳統直接暴露原始黨讓 browser / robots 讀取的 html 頁面.</p>
<p>許多案子紛紛的靠往 Ajax 網站而捨棄 flash, 為求生存, Flash based website 除了要提供更複雜的設計需求, 還必須要解決本身在 SEO / Diret Link 不如 html 的缺失, 所以就出現了熱門的 DeepLinking (DL) 的機制, 以 SWFAddress 為大宗.</p>
<p>如此一來解決了所有內容包含在 Flash 內的困擾, 讓 URL 上的網址可以對應到相關的 Flash 頁面.</p>
<p>相信有做過 DL 的人都知道, 要完全的雙向 DL, 是寫 AS3 的一大挑戰,除了要儘可能的做到絢麗的互動設計之外,還要兼顧到 DL 的機制, 更進一步如果要有SEO的能視度, 相對應的資料處理變得相當複雜.</p>
<p>其實利用 MVC Pattern, 整個分工可以變得比較清楚,尤其最近跟康貓兄搞了一點 CakePHP, 其用 Controller 與 View 配對的機制, 打通了不少之前在 Flash 上, View 與 Control 之間糾纏的問題.</p>
<p>以下是小弟我的心得怕忘記,寫下來,並跟大家分享:</p>
<p><span id="more-1198"></span></p>
<p>基本上, 在製作 DL 的時候,如果從最基本的觀念出發,就是一切由URL控制,最理想的狀況就是,所有Flash內部的任何動作,都只是改變網址,經由網址的變化 Event, 觸發頁面的改變.</p>
<p>概念有了,就比較簡單一點點了,再來就是實作上的訣竅.</p>
<p>一般而言網站的目的就是包裝資訊,然而這整個資訊的結構可能相當龐大,因此我們要根據一些分類法把網站加以分類,讓人方便並且容易了解,分類之後在依據策略做互動界面的安排.(這些類工作就是所謂 information architect / interaction design 的責任, 很多人都把 interaction design,誤認為製作好玩的互動界面,其實共做內容大多是在設計流程圖)</p>
<p>經過以上動作之後,網站會有幕後看不道的整筆 1.data, 在實體上就會形成兩樣重要的視覺元素, 2.navigation system and 3.content.</p>
<p>我們可以用 MVC 的方式來讓這三個元素既達到視覺設計上的突破,也能完成DL/SEO功能上的要求. 並且至做出來的模組,也可以重複使用,減低每次重做的痛苦.</p>
<p>&#8220;-&gt;&#8221;資料流向<br />
&#8220;&gt;&gt;&#8221;動作順序</p>
<p>Model<br />
1.data: 資料分割,並且提供統一的資訊回應 API, 資訊包裝回應,避免耦合. (data -&gt; relationship logic -&gt; information),幫裝不一過多或過少,這也同時會影響 SEO,搜尋的結果.</p>
<p>Controller<br />
接受 SWFAddress 的網址改變 Event,觸發:</p>
<p><span style="text-decoration: underline;">(0).拿資料 : M-&gt;C: 先把View要的資料蒐集完畢,然後發出事件改變 View.(蒐集資料也可以發生在 View,視情況而定)</span><br />
翻譯網址改成 Model API 需要的語法, 索取Model裡面分割好的information,簡單來說,一個網址就是配一個包裝過的資訊單位,也就是 transition -&gt; 最後完畢提供資訊的界面所需要的, 基本上網址對應的內容可以後來再讀,但是 navigation / 互動元素, 要用到的必須先準備好.</p>
<p><span style="text-decoration: underline;">1.做改變 : C&gt;&gt;V: 跟據網址發出事件給 V<br />
</span>需要過濾網址格式是否正確,否則會造成混淆與錯誤.</p>
<p><span style="text-decoration: underline;">2.給資料 : 提供API,反應 V 要改變的資料</span></p>
<p>View<br />
content: 消失上一筆內容, 接收網址顯示內容.<br />
navigation: 接收網址改變, 或是改變網址.</p>
<p>在處理 navigation 必須要能直接跳頁, 而並非依序漸進, 像是 start &gt;&gt; 1 &gt;&gt; 1-3 （這種依序漸進的方式不宜採用),必須要有 start at 2-3 &gt;&gt; 3-2 &gt;&gt; 2-1.</p>
<p>DL通常用在一開始就有網址進來,可以把 audience,直接帶到該頁內容,這種狀況要擋住一開始近來的事件,先把所有的 Menu 內容準備好,在去觸發,不然會造成 Menu 無法應變.<br />
Menu 內容已知,數量不多的時候, 可以一次把所有的 Menu 建出來,但是不要秀出來, 已備跳頁的狀況</p>
<p>最後的挑戰就是必需要考慮到循序見儘可能產生的transition,與跳頁的時候,要如何安排可能產生的問題.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.silkrt.com/v01/2008/11/08/as3%e7%ad%86%e8%a8%98-dlmvc%e6%8e%a7%e5%88%b6%e5%bf%83%e5%be%97/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>AS3筆記-難題</title>
		<link>http://www.silkrt.com/v01/2008/10/31/as3%e7%ad%86%e8%a8%98-%e9%9b%a3%e9%a1%8c/</link>
		<comments>http://www.silkrt.com/v01/2008/10/31/as3%e7%ad%86%e8%a8%98-%e9%9b%a3%e9%a1%8c/#comments</comments>
		<pubDate>Fri, 31 Oct 2008 07:39:48 +0000</pubDate>
		<dc:creator>Marc</dc:creator>
				<category><![CDATA[flash]]></category>
		<category><![CDATA[small]]></category>
		<category><![CDATA[as3.0]]></category>
		<category><![CDATA[question]]></category>

		<guid isPermaLink="false">http://www.silkrt.com/v01/?p=1169</guid>
		<description><![CDATA[我在寫一個 function &#8211; 輸入一個矩形區域的長寬,及想要蜂巢型平均分布元件數量,想要得到的是每個元件位置的陣列串,算了一整天都還是沒有好的結果(如圖示),不知是否有高手可以解決？（得到直列一排有幾個就可以了,排列的方法我已經弄出來了)

]]></description>
			<content:encoded><![CDATA[<p>我在寫一個 function &#8211; 輸入一個矩形區域的長寬,及想要蜂巢型平均分布元件數量,想要得到的是每個元件位置的陣列串,算了一整天都還是沒有好的結果(如圖示),不知是否有高手可以解決？（得到直列一排有幾個就可以了,排列的方法我已經弄出來了)</p>
<p><a class="flickr-image" title="fill dots" rel="flickr-mgr" href="http://www.flickr.com/photos/22606320@N02/2988006991/"><img class="flickr-medium" src="http://farm4.static.flickr.com/3271/2988006991_d917cd9809.jpg" alt="fill dots" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.silkrt.com/v01/2008/10/31/as3%e7%ad%86%e8%a8%98-%e9%9b%a3%e9%a1%8c/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>mediaMultiMedia</title>
		<link>http://www.silkrt.com/v01/2008/10/28/mediamultimedia/</link>
		<comments>http://www.silkrt.com/v01/2008/10/28/mediamultimedia/#comments</comments>
		<pubDate>Wed, 29 Oct 2008 01:00:49 +0000</pubDate>
		<dc:creator>Marc</dc:creator>
				<category><![CDATA[flash]]></category>
		<category><![CDATA[small]]></category>
		<category><![CDATA[as3.0]]></category>

		<guid isPermaLink="false">http://www.silkrt.com/v01/?p=1149</guid>
		<description><![CDATA[
Just forgot to mention that I made a blog for my new prefix &#8220;professor&#8221; in Kean university.
If you are interested in learning flash or checking out some AS3 for Flash IDE example I used in class, you can go to mediamultimedia.wordpress.com
If you are pretty new to Flash / AS3, there are some Flash IDE based [...]]]></description>
			<content:encoded><![CDATA[<p><img style="border: 0pt none;" src="http://mediamultimedia.files.wordpress.com/2008/10/picture-1.png" alt="" width="435" /></p>
<p>Just forgot to mention that I made a blog for my new prefix &#8220;professor&#8221; in <a href="http://www.kean.edu/" target="_blank">Kean university</a>.</p>
<p>If you are interested in learning flash or checking out some AS3 for Flash IDE example I used in class, you can go to <a href="http://mediamultimedia.wordpress.com/" target="_blank">mediamultimedia.wordpress.com</a></p>
<p>If you are pretty new to Flash / AS3, there are some Flash IDE based examples in class blog for people to download.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.silkrt.com/v01/2008/10/28/mediamultimedia/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>AS3筆記-三名詭異</title>
		<link>http://www.silkrt.com/v01/2008/10/17/as3%e7%ad%86%e8%a8%98-%e4%b8%89%e5%90%8d%e4%b8%bb%e6%84%8f/</link>
		<comments>http://www.silkrt.com/v01/2008/10/17/as3%e7%ad%86%e8%a8%98-%e4%b8%89%e5%90%8d%e4%b8%bb%e6%84%8f/#comments</comments>
		<pubDate>Fri, 17 Oct 2008 07:33:34 +0000</pubDate>
		<dc:creator>Marc</dc:creator>
				<category><![CDATA[flash]]></category>
		<category><![CDATA[small]]></category>
		<category><![CDATA[as3.0]]></category>

		<guid isPermaLink="false">http://www.silkrt.com/v01/?p=1107</guid>
		<description><![CDATA[最近在Kean University教 multimedia programming, 學生怪問題一堆, 也讓我發現了平常沒有注意到的事情&#8230;
不曉得大家有沒有發現 物件有很多名字, 屏除 library 的 symbol name 不管,有
1.class name: linkage 的 className(.as)
2.variable name: var variableName:className = new className();
3.instance name: 在Flash IDE 裡面, 如果東西直接放在stage上, 要 assign &#60;instance name&#62;,
或是 var a:A=new A(); a.name=&#8221;apple&#8221;;
奇怪的問題出現了&#8230;.

畫一個方形,建立linkage,class name叫 &#8220;square&#8221; (應該是要字首大寫啦,不過測試隨便)

拉一個物件到stage, name it &#8220;sq1&#8243; -&#62; instance name

另外拉一個不命名

測試結果:
直接手動拉到stage的物件並且命名的,可以用該instance name直接代表該物件設定 property,像是 .x, .y等等,那個 instance name 就代表該物件
直接手動拉到stage的物件但沒有命名的,不可以用自動 assign 的 &#8220;instanceN&#8221; [...]]]></description>
			<content:encoded><![CDATA[<p>最近在Kean University教 multimedia programming, 學生怪問題一堆, 也讓我發現了平常沒有注意到的事情&#8230;</p>
<p>不曉得大家有沒有發現 物件有很多名字, 屏除 library 的 symbol name 不管,有</p>
<p>1.class name: linkage 的 className(.as)</p>
<p>2.variable name: var variableName:className = new className();</p>
<p>3.instance name: 在Flash IDE 裡面, 如果東西直接放在stage上, 要 assign &lt;instance name&gt;,<br />
或是 var a:A=new A(); a.name=&#8221;apple&#8221;;</p>
<p>奇怪的問題出現了&#8230;.<span id="more-1107"></span></p>
<p><a title="建立linkage的 symbol(class) by silkrt.com, on Flickr" href="http://www.flickr.com/photos/silkrt/2949077154/"><img src="http://farm4.static.flickr.com/3069/2949077154_df0d839ab1_o.png" alt="建立linkage的 symbol(class)" width="517" height="305" /></a></p>
<p>畫一個方形,建立linkage,class name叫 &#8220;square&#8221; (應該是要字首大寫啦,不過測試隨便)</p>
<p><a title="命名的instance by silkrt.com, on Flickr" href="http://www.flickr.com/photos/silkrt/2949077066/"><img src="http://farm4.static.flickr.com/3145/2949077066_2cfb231b23_o.png" alt="命名的instance" width="283" height="380" /></a></p>
<p>拉一個物件到stage, name it &#8220;sq1&#8243; -&gt; instance name</p>
<p><a title="未命名的instance by silkrt.com, on Flickr" href="http://www.flickr.com/photos/silkrt/2949077106/"><img src="http://farm4.static.flickr.com/3175/2949077106_e3be4a85b5_o.png" alt="未命名的instance" width="406" height="375" /></a></p>
<p>另外拉一個不命名</p>
<p><a title="測試 by silkrt.com, on Flickr" href="http://www.flickr.com/photos/silkrt/2949077302/"><img src="http://farm4.static.flickr.com/3144/2949077302_e187a33c63_b.jpg" alt="測試" width="1024" height="692" /></a></p>
<p>測試結果:</p>
<p>直接手動拉到stage的物件並且命名的,<span style="color: #ff00ff;">可以</span>用該instance name直接代表該物件設定 property,像是 .x, .y等等,那個 <span style="color: #ff00ff;">instance name 就代表該物件</span></p>
<p>直接手動拉到stage的物件但沒有命名的,<span style="color: #ff00ff;">不可以</span>用自動 assign 的 &#8220;instanceN&#8221; 設定 property. 如果圖裡面的 code 加上<br />
instance2.x=100; //1120: Access of undefined property instance2. 會有錯誤,所以手動放的東西一定要命名而且不能用程式去改&#8230;</p>
<p>AS new出來的然後用 .name = 去命名,<span style="color: #ff00ff;">不可以</span>用那個 instance name去設定 property, 只能用 variable name.</p>
<p>AS new出來,用 AS 自動命名的 instanceN,<span style="color: #ff00ff;">不可以</span>用那個 instance name去設定 property, 只能用 variable name.</p>
<p>上圖測試加上 instance6.x=100; //1120: Access of undefined property instance6.</p>
<p>邏輯在哪裡,用中文都很難解釋了&#8230;. 真的.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.silkrt.com/v01/2008/10/17/as3%e7%ad%86%e8%a8%98-%e4%b8%89%e5%90%8d%e4%b8%bb%e6%84%8f/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>AS3筆記-get stage</title>
		<link>http://www.silkrt.com/v01/2008/09/30/as3%e7%ad%86%e8%a8%98-get-stage-from-subclasses/</link>
		<comments>http://www.silkrt.com/v01/2008/09/30/as3%e7%ad%86%e8%a8%98-get-stage-from-subclasses/#comments</comments>
		<pubDate>Tue, 30 Sep 2008 05:41:00 +0000</pubDate>
		<dc:creator>Marc</dc:creator>
				<category><![CDATA[flash]]></category>
		<category><![CDATA[small]]></category>
		<category><![CDATA[as3.0]]></category>

		<guid isPermaLink="false">http://www.silkrt.com/v01/?p=1001</guid>
		<description><![CDATA[If you want to build something like keyboard shortcut or want to catch global mouse activity, you might need to use

stage.addEventListener(KeyboardEvent.KEY_DOWN,onKeyPressed);
//or
stage.addEventListener(MouseEvent.CLICK,onMouseClicked);

You might need to access &#8220;stage&#8221; from sub-classes. To get &#8220;stage&#8221; from document class you can try:

addEventListener(Event.ADDED_TO_STAGE, onAddStage);
private function onAddStage(evt:Event):void{
//var myParent:Sprite=Sprite(evt.target)
//myParent.stage.addEventListener(KeyboardEvent.KEY_DOWN,onKeyPressed);
//sprite裡面的stage property 已經可以因為被放到Stage的事件之後被使用
this.stage.addEventListener(KeyboardEvent.KEY_DOWN,onKeyPressed);
}

]]></description>
			<content:encoded><![CDATA[<p>If you want to build something like keyboard shortcut or want to catch global mouse activity, you might need to use</p>
<pre class="brush: as3; title: ; notranslate">
stage.addEventListener(KeyboardEvent.KEY_DOWN,onKeyPressed);
//or
stage.addEventListener(MouseEvent.CLICK,onMouseClicked);
</pre>
<p>You might need to access &#8220;stage&#8221; from sub-classes. To get &#8220;stage&#8221; from document class you can try:</p>
<pre class="brush: as3; title: ; notranslate">
addEventListener(Event.ADDED_TO_STAGE, onAddStage);
private function onAddStage(evt:Event):void{
//var myParent:Sprite=Sprite(evt.target)
//myParent.stage.addEventListener(KeyboardEvent.KEY_DOWN,onKeyPressed);
//sprite裡面的stage property 已經可以因為被放到Stage的事件之後被使用
this.stage.addEventListener(KeyboardEvent.KEY_DOWN,onKeyPressed);
}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.silkrt.com/v01/2008/09/30/as3%e7%ad%86%e8%a8%98-get-stage-from-subclasses/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>AS3筆記-DisObj,Reference,GC</title>
		<link>http://www.silkrt.com/v01/2008/08/14/as3%e7%ad%86%e8%a8%98-disobjreferencegc/</link>
		<comments>http://www.silkrt.com/v01/2008/08/14/as3%e7%ad%86%e8%a8%98-disobjreferencegc/#comments</comments>
		<pubDate>Thu, 14 Aug 2008 05:24:39 +0000</pubDate>
		<dc:creator>Marc</dc:creator>
				<category><![CDATA[flash]]></category>
		<category><![CDATA[small]]></category>
		<category><![CDATA[as3.0]]></category>

		<guid isPermaLink="false">http://www.silkrt.com/v01/?p=778</guid>
		<description><![CDATA[如果今天new一個DisplayObject然後reference給一個property variable,addChild,之後 removeChild 然後那個property variable又reference給另一個DisplayObject.
那原先的DisplayObject就再也access不到了對吧？ 這樣子Garbage Collection會釋放出記憶體嗎？
不管有沒有 把 reference 先設成 null,再重新 reference, GC都會把他清掉.只是快慢問題而已.好像沒有記憶體越用越多的問題&#8230;.
ex:
b=new SpriteClassA();
a.addChild(b);
b.remove()//自己fadeout之後 parent.removeChild(this)
b=new SpriteClassB();
a.addChild(b);

我的測試方法是把一個包著一張大圖得Sprite,addChild1000次,左下角按鈕會remove掉再執行一次.
測試main.swf (請把視窗拉小再按左下角的按鈕）

package {
import flash.system.*;
import flash.display.*;
import flash.events.*;
public class Main extends MovieClip {
public var yy:Number=0;
//public reference to the root
public var b:Sprite;
public function Main():void {
this.btn.addEventListener(MouseEvent.CLICK,putNewImage);
addEventListener(Event.ENTER_FRAME,checkMem);
}

public function putImg():void {
b=new Sprite();
addChild(b);
yy+=5;
for (var i:int=0; i&#38;amp;amp;amp;amp;amp;lt;1000; i++) {
var a:Sprite=new img();
a.x+=i*0.1;
a.alpha =a.x/1000;
a.y=yy;
b.addChild(a);
}
}

public function putNewImage(evt:Event=null) {
trace(this.numChildren);
if (this.numChildren&#62;1) {
this.removeChildAt(1);
b=null;//comment this [...]]]></description>
			<content:encoded><![CDATA[<p>如果今天new一個DisplayObject然後reference給一個property variable,addChild,之後 removeChild 然後那個property variable又reference給另一個DisplayObject.</p>
<p>那原先的DisplayObject就再也access不到了對吧？ 這樣子Garbage Collection會釋放出記憶體嗎？</p>
<p>不管有沒有 把 reference 先設成 null,再重新 reference, GC都會把他清掉.只是快慢問題而已.好像沒有記憶體越用越多的問題&#8230;.</p>
<p>ex:</p>
<p>b=new SpriteClassA();</p>
<p>a.addChild(b);</p>
<p>b.remove()//自己fadeout之後 parent.removeChild(this)</p>
<p>b=new SpriteClassB();</p>
<p>a.addChild(b);</p>
<p><span id="more-778"></span></p>
<p>我的測試方法是把一個包著一張大圖得Sprite,addChild1000次,左下角按鈕會remove掉再執行一次.</p>
<p><a href="http://www.silkrt.com/v01/wp-content/uploads/2008/08/main.swf">測試main.swf (請把視窗拉小再按左下角的按鈕）</a></p>
<pre class="brush: as3; title: ; notranslate">
package {
import flash.system.*;
import flash.display.*;
import flash.events.*;
public class Main extends MovieClip {
public var yy:Number=0;
//public reference to the root
public var b:Sprite;
public function Main():void {
this.btn.addEventListener(MouseEvent.CLICK,putNewImage);
addEventListener(Event.ENTER_FRAME,checkMem);
}

public function putImg():void {
b=new Sprite();
addChild(b);
yy+=5;
for (var i:int=0; i&amp;amp;amp;amp;amp;amp;lt;1000; i++) {
var a:Sprite=new img();
a.x+=i*0.1;
a.alpha =a.x/1000;
a.y=yy;
b.addChild(a);
}
}

public function putNewImage(evt:Event=null) {
trace(this.numChildren);
if (this.numChildren&gt;1) {
this.removeChildAt(1);
b=null;//comment this line will show auto GC
}
putImg();
}

public function checkMem(evt:Event):void {
this.btn.label=String(Math.ceil(System.totalMemory/1000));
}
}
}
</pre>
<p><a href="http://www.silkrt.com/v01/wp-content/uploads/2008/08/main2.swf">測試main2.swf（請把視窗拉小一點-&gt;請按左下角按鈕）</a></p>
<p>week reference測試:</p>
<pre class="brush: as3; title: ; notranslate">
package {
import flash.system.*;
import flash.display.*;
import flash.events.*;

public class Main2 extends MovieClip {
public var yy:Number=0;

public function Main2():void {
this.btn.addEventListener(MouseEvent.CLICK,putNewImage);
addEventListener(Event.ENTER_FRAME,checkMem);
}

public function putImg():void {
//Weak reference:
var b:Sprite=new Sprite();
addChild(b);
yy+=5;
for (var i:int=0; i&amp;amp;amp;amp;amp;amp;lt;1000; i++) {
var a:Sprite=new img();
a.x+=i*0.1;
a.alpha =a.x/1000;
a.y=yy;
b.addChild(a);
}
}

public function putNewImage(evt:Event=null) {
trace(this.numChildren);
if (this.numChildren&gt;1) {
var c:*=this.getChildAt(1);
this.removeChildAt(1);
c=null;//comment this line will show auto GC
}
putImg();
}

public function checkMem(evt:Event):void {
this.btn.label=String(Math.ceil(System.totalMemory/1000));
}
}
}
</pre>
<p><a href="http://www.silkrt.com/v01/wp-content/uploads/2008/08/archive.zip">test file(zip)</a></p>
<p>減少變因測:</p>
<pre class="brush: as3; title: ; notranslate">
package {
import flash.system.*;
import flash.display.*;
import flash.events.*;
public class Main3 extends MovieClip {
public var yy:Number=0;
public var a:Sprite
public function Main3():void {
this.btn.addEventListener(MouseEvent.CLICK,putNewImage);
addEventListener(Event.ENTER_FRAME,checkMem);
}
public function putImg():void {
for (var i:int=0; i&amp;amp;amp;lt;1000; i++) {
a=new img();////重複指定新img,reference給a;
}
}
public function putNewImage(evt:Event=null) {
putImg();
}
function checkMem(evt:Event):void {
this.btn.label=String(Math.ceil(System.totalMemory/1000));
}
}
}
</pre>
<p>在沒有任何EventListener之下,還是被清掉,看來我多心了&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.silkrt.com/v01/2008/08/14/as3%e7%ad%86%e8%a8%98-disobjreferencegc/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>AS3筆記-運動複習</title>
		<link>http://www.silkrt.com/v01/2008/08/06/as3%e7%ad%86%e8%a8%98-%e9%81%8b%e5%8b%95%e8%a4%87%e7%bf%92/</link>
		<comments>http://www.silkrt.com/v01/2008/08/06/as3%e7%ad%86%e8%a8%98-%e9%81%8b%e5%8b%95%e8%a4%87%e7%bf%92/#comments</comments>
		<pubDate>Wed, 06 Aug 2008 17:55:50 +0000</pubDate>
		<dc:creator>Marc</dc:creator>
				<category><![CDATA[flash]]></category>
		<category><![CDATA[small]]></category>
		<category><![CDATA[as3.0]]></category>

		<guid isPermaLink="false">http://www.silkrt.com/v01/?p=748</guid>
		<description><![CDATA[Click here to view the embedded video.
自從用了 TweeningEngine 之後,就漸漸忘了從前用 EnterFrame是怎麼寫物體運動的, 趁現在還記得, 放在這邊備忘&#8230;


//ball1減速, ball2 彈力
addEventListener(Event.ENTER_FRAME,onEnterFrame);
var tx:Number=0;
var ty:Number=0;
function onEnterFrame(evt:Event) {
//減速 : 目前位置+=(目的地-目前位置)*變化量
ball1.x+=(stage.mouseX-ball1.x)*0.2;
ball1.y+=(stage.mouseY-ball1.y)*0.2;
//彈力 : 目前位置 += (減速變數 - 目前位置)*變化量
tx+=(stage.mouseX-ball2.x)*0.5;
ball2.x+=(tx-ball2.x)*0.2;
ty+=(stage.mouseY-ball2.y)*0.5;
ball2.y+=(ty-ball2.y)*0.2;
}

]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.silkrt.com/v01/2008/08/06/as3%e7%ad%86%e8%a8%98-%e9%81%8b%e5%8b%95%e8%a4%87%e7%bf%92/"><em>Click here to view the embedded video.</em></a></p>
<p>自從用了 TweeningEngine 之後,就漸漸忘了從前用 EnterFrame是怎麼寫物體運動的, 趁現在還記得, 放在這邊備忘&#8230;</p>
<p><span id="more-748"></span></p>
<pre class="brush: as3; title: ; notranslate">
//ball1減速, ball2 彈力
addEventListener(Event.ENTER_FRAME,onEnterFrame);
var tx:Number=0;
var ty:Number=0;
function onEnterFrame(evt:Event) {
//減速 : 目前位置+=(目的地-目前位置)*變化量
ball1.x+=(stage.mouseX-ball1.x)*0.2;
ball1.y+=(stage.mouseY-ball1.y)*0.2;
//彈力 : 目前位置 += (減速變數 - 目前位置)*變化量
tx+=(stage.mouseX-ball2.x)*0.5;
ball2.x+=(tx-ball2.x)*0.2;
ty+=(stage.mouseY-ball2.y)*0.5;
ball2.y+=(ty-ball2.y)*0.2;
}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.silkrt.com/v01/2008/08/06/as3%e7%ad%86%e8%a8%98-%e9%81%8b%e5%8b%95%e8%a4%87%e7%bf%92/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
<!-- WP Super Cache is installed but broken. The path to wp-cache-phase1.php in wp-content/advanced-cache.php must be fixed! -->
