2011-08-17

第六回AS讀書會之簡報果然好難!

昨天(8/16)是第六次的讀書會,小弟我因為上次寫了這篇文章後,就很厚臉皮地跟龍哥說想要上台分享。

原本我想說上台分享就像是跟大家聊天一樣,應該蠻輕鬆的,但是!!

人生最可怕的就是這個「但是」了!!


2011-06-15

動態建立物件

今天在噗浪上看到卡卡米問了一個問題使用 Class 類別動態建立物件的建構式參數。 

如果要用 AS3 動態建立物件其實很簡單:

public function createInstance(theClass:Class):* {
  return new theClass();
}


2011-05-06

Parsley - An AS3 Framework

目前 AS3 比較熱門的 Framework 有:PureMVC, Robotlegs, ... 等等。

Adobe 官方也有一套 Cairngorm,不過它自從 2007 年後就停止更新了。

之前因為專案的關係而有接觸過。因為當初 AS3 Framework 的選擇並不多(應該說雖然有很多冒出頭,但都還在 alpha, beta 階段,或是根本很少人用),加上 Cairngorm 有著官方的加持,所以當初就選擇它來使用。但是用過的感覺並不是很好,覺得是個很「囉唆」的Framework(難怪後來就沒有更新了)。
之後的專案我就改用了當時的第二個選項:PureMVC。用了之後就覺得這 Framework 太妙了!沒有之前使用 Caringrom 的沈重感。而且更妙的是它有 port 到其他語言上,所以有次 C# 的專案我也拿 PureMVC 來練練身體 :D

某天我心血來潮,想看看很久沒動的 Cairngrom 目前狀況如何(有種想要窺探初戀情人現在如何的心情),才知道它還活著但是不再發展了。取而代之的是完全以「開發指導」自居的 Cairngorm 3

當然本篇的重點不是 Cairngorm,不然看倌們一定會以為我打錯標題了。關於 Cairngrom 3 的一些細節,這邊就不提了,請各位移駕到這裡參詳。

之所以會提到 Cairngorm ,是當我在瀏覽 Cairngorm 3 的時候,發現它提供了許多工具都是針對 Parsley,這就我讓我很好奇這是一個甚麼樣的 Framework。所以我 google 了一下然後到官方網站看看文件(題外話,原來 parsley 的翻譯有這麼多的分歧!?),整理一下心得分享給大家囉!


2010-08-12

RemoteService

Recently I was working on some projects using Flex and PureMVC. It's wonderful when using PureMVC to build a Flex application. It makes things easier!!

Here is an example that using Remoting with PureMVC. In this demo, it uses a Delegate class to call the remote methods, and the Proxy class calls the Delegate class method to get data. As you can see, there are two same methods in two classes, and all methods in the Delegate class are almost the same, except there are different method names and different parameters.

It's good to use Delegate class when one day you want to change the way you get data, using WebService instead of RemoteObject, for example. It is easier to make changes.

But it still bothers me.

So I created my own class to make using RemoteObject easier.

Below is the code:

package cc.hayama.services {
import mx.rpc.remoting.mxml.RemoteObject;
import mx.rpc.remoting.Operation;
import mx.rpc.IResponder;
import mx.rpc.AsyncToken;

public class RemoteService {

private var service:RemoteObject;

public function RemoteService(destination:String):void {       
this.service = new RemoteObject();
this.service.showBusyCursor = true;
this.service.destination = destination;      
}

public function set endpoint(value:String):void { service.endpoint = value;}
public function get endpoint():String { return service.endpoint; }

public function set source(value:String):void { service.source = value; }
public function get source():String { return service.source; }

public function call(responder:IResponder, methodName:String, ...args):void {
var token:AsyncToken;
var op:Operation;

op = service.getOperation(methodName) as Operation;
op.arguments = args;

token = op.send();
token.addResponder(responder);
}
}
}

And you can use it like this:
private function onHelloReslut(event:ResultEvent):void {
...
}
private function onFault(event:FaultEvent):void {
...
}
var service:RemoteService = new RemoteService("test");
service.source = "Hello";
service.call(new mx.rpc.Responder(onHelloResult, onFault), "say", "hello");

The point is that I used a "...args" parameter in call method.

With this **magic** parameter, I can call the remote method and pass any numbers and any types of parameters, using just one call method!!


2009-04-24

如何降低 Flex 發佈出來的 swf 檔案大小

這個應該不是什麼新消息或是新技巧了。

簡單講就是利用 Flash Player Cache 搭配 RSL,將 Flex Framework 獨立出來,已達到減低發佈出來的 swf 檔案大小的效果(參考官方說明文件)。

只是剛剛不小心翻到這篇文章,覺得很好笑,特地註記一下:D