2007年10月28日星期日

兩種使用 Flash 開發 Flex Skin 方式比較   [+/-]

Ticore's Blog

一般在 Flex 中使用外部 Graphical Skin
都是用 Embed 標籤來嵌入外部 SWF or PNG、JPG....
假如以 Flash 整合,可以用更方便的做法

那便是用 Flash 輸出 SWC 類別庫之後
直接在 Flex 內引用 Symbol Class
優點如下:

  • 不必額外撰寫 Embed 標籤
  • 可以保留 Flash Symbol 內的 ActionScript (使用 Embed 無法保留 Symbol AS)
  • 具有較好的程式碼提示功能

保留 ActionScript,意味著可以同時混和 Graphical Skin、Programmatic Skin
直接作出 Hybrid Skin,有些情況會很方便

相關連結:
用 Flash 開發 Flex Skin 才是王道
在 Flash 作點陣圖九宮格縮放技巧
Flex Embed 點陣圖檔小技巧
Flex Embed 外部資源技巧

Read more...

2007年10月26日星期五

AS3 技巧 - 利用 Flex Builder 編譯 Flash 相容 SWC 類別庫   [+/-]

Ticore's Blog

原文網址:Compiling Flash CS3 compatible SWC's with Flex

之前我也曾經嚐試過利用 Flex Builder 編譯 SWC 類別庫
拿到 Flash CS3 用,結果失敗
這文章作者指出了一些 Flex 編譯 SWC 的關鍵步驟
照著做出來的 SWC 就可以拿到 Flash CS3 使用了

至於為什麼要用 Flex 編譯 SWC
如作者所述
Flex 開發環境比較好用,可以與 Ant 結合,容易建立~

另外,用 Flash CS3 編譯 SWC Lib. 時
必須要在 Component Main Class 明確引用需要包入的 Class
否則 Flash CS3 是不會把其它 Class 編譯進去的
這點在 Flex 方便多了,有 GUI 介面可以自由選擇 Class

關鍵步驟如下:

  • 建立 Flex Lib. Project
  • 加入編譯參數 -compute-digest=false
  • 建立並且指定編譯參數 manifest.xml
  • manifest.xml:

    <?xml version="1.0" encoding="utf-8" ?>
    <componentPackage>
      <component id="[Component Name]" class="[Component Main Class]"/>
    </componentPackage>
    

Read more...

2007年10月21日星期日

自製 DisplayObjectProxy Class - 快速遊走於 DisplayObject Tree   [+/-]

Ticore's Blog

ActionScript 3.0 的 DisplayObject、DisplayObjectContainer 相關操作
變的相當嚴謹,同時也相當擾民啊
沒有先作檢查,沒有作好轉型動作
就會得到一堆 Error~~

假如遇到相當複雜的 DisplayObject Tree 結構
那恐怕要寫很多程式作檢查與轉型的動作了...

以下是利用 AS3 Proxy Class 簡化 DisplayObject Tree 操作

AS3 DisplayObjectProxy Class:

/*//

AS3 DisplayObjectProxy Class, version 0.0.1
(c) 2007 Shih, Wei-Lung <weilung_shih@hotmail.com>

AS3 DisplayObjectProxy Class is freely distributable
  under the terms of an GNU license.
For details, see the Prototype web site: http://ticore.blogspot.com/

//*/
package {

 import flash.display.*;
 import flash.utils.*;

 public dynamic class DisplayObjectProxy extends Proxy {
  
  protected var _target_:DisplayObject;
  protected var _keys_:Array;
  protected var _values_:Array;
  
  protected var disObjCont:DisplayObjectContainer;
  
  public function DisplayObjectProxy(target:DisplayObject):*{
   this._target_ = target;
   this.disObjCont = _target_ as DisplayObjectContainer;
  }
  
  flash_proxy override function hasProperty(propName:*):Boolean {
   //trace("hasProperty : " + propName);
   return true;
  }
  
  flash_proxy override function getProperty(propName:*):* {
   //trace("getProperty : " + propName);
   
   var no:Number = parseInt(propName);
   var isUint:Boolean = (no as uint) == no;
   
   if (disObjCont != null) {
    var child:DisplayObject = null;
    if (isUint) {
     if (disObjCont.numChildren > no) {
      child = disObjCont.getChildAt(no);
     }
     //trace("child : " + child);
     if (child != null) {
      return new DisplayObjectProxy(child);
     } else {
      return null;
     }
    }
    
    //trace("disObjCont : " + disObjCont);
    child = disObjCont.getChildByName(propName);
    //trace("child : " + child);
    if (child != null) {
     return new DisplayObjectProxy(child);
    }
   }
   
   var prop:* = _target_[propName];
   if (prop is DisplayObject) {
    return new DisplayObjectProxy(prop);
   } else {
    return prop;
   }
   
  }
  
  
  flash_proxy override function setProperty(propName:*, valueObj:*):void {
   //trace("setProperty : " + propName, valueObj);
   
   var no:Number = parseInt(propName);
   var isUint:Boolean = (no as uint) == no;
   
   
   if (_target_.hasOwnProperty(propName)) {
    _target_[propName] = valueObj;
    return;
   }
   
   if (disObjCont != null) {
    if (valueObj is DisplayObject) {
     if (isUint) {
      if(disObjCont.numChildren > no) {
       disObjCont.removeChildAt(no);
      }
      disObjCont.addChildAt(valueObj, no);
     }
    }
    if (valueObj == null) {
     if (isUint) {
      if(disObjCont.numChildren > no) {
       disObjCont.removeChildAt(no);
      }
     }
    }
   }
   
  }
  
  flash_proxy override function deleteProperty(propName:*):Boolean {
   //trace("deleteProperty : " + propName);
   
   var no:Number = parseInt(propName);
   var isUint:Boolean = (no as uint) == no;
   
   if (disObjCont != null) {
    if (isUint) {
     if(disObjCont.numChildren > no) {
      disObjCont.removeChildAt(no);
      return true;
     }
    }
   }
   return false;
  }
  
  
  flash_proxy override function callProperty(propName:*, ... rest):* {
   //trace("callProperty : " + propName);
   return _target_[propName].apply(_target_, rest);
  }
  
  override flash_proxy function nextNameIndex (index:int):int {
   //trace("nextNameIndex : " + index);
   
   if (index == 0) {
    _keys_ = new Array();
    _values_ = new Array();
    if (disObjCont != null) {
     var o:DisplayObject;
     for (var i:Number = 0 ; i < disObjCont.numChildren ; ++i) {
      o = disObjCont.getChildAt(i);
      _keys_.push(o.name);
      _values_.push(o);
     }
    }
   }
   if (index < _keys_.length) {
    return index + 1;
   } else {
    return 0;
   }
  }
  
      override flash_proxy function nextName(index:int):String {
   //trace("nextName : " + index);
   return _keys_[index - 1];
  }
  
      override flash_proxy function nextValue(index:int):* {
   //trace("nextValue : " + index);
   return _values_[index - 1];
  }
  
 }
}

DisplayObjectProxy Class 使用範例:

package {
 
 import flash.display.*;
 import flash.utils.*;
 
 public dynamic class main extends MovieClip {
  
  public function main():*{
   test();
  }
  
  public function test():*{
   
   // 將 Main 包覆為 DisplayObjectProxy
   var mainProxy:* = new DisplayObjectProxy(this);
   
   // 用 DisplayObjectProxy 加入四個 Child MovieClip
   mainProxy[0] = new MovieClip();
   mainProxy[1] = new MovieClip();
   mainProxy[2] = new MovieClip();
   mainProxy[3] = new MovieClip();
   
   trace(this.numChildren); // 4
   
   // 用 DisplayObjectProxy 指定四個 Child MovieClip Name
   mainProxy[0].name = "mc1";
   mainProxy[1].name = "mc2";
   mainProxy[2].name = "mc3";
   mainProxy[3].name = "mc4";
   
   
   // 用 DisplayObjectProxy 依據 Child Name 取出物件
   trace(mainProxy["mc4"].name); // mc4
   
   
   trace(this.getChildAt(0).name); // mc1
   trace(this.getChildAt(1).name); // mc2
   trace(this.getChildAt(2).name); // mc3
   trace(this.getChildAt(3).name); // mc4
   
   
   
   // 用 DisplayObjectProxy 移除 index 為 2 的 child 方式之一
   mainProxy[2] = null;
   
   // 用 DisplayObjectProxy 列舉所有的 children 方式之一
   for (var i:* in mainProxy) {
    trace(i);
   }
   // mc1
   // mc2
   // mc4
   
   
   // 用 DisplayObjectProxy 移除 index 為 2 的 child 方式之二
   delete mainProxy[2];
   
   // 用 DisplayObjectProxy 列舉所有的 children 方式之二
   for each(var o:* in mainProxy) {
    trace(o.name);
   }
   // mc1
   // mc2
   
   
   // 用 DisplayObjectProxy 對子物件容器再加入 Child
   mainProxy[0][0] = new MovieClip();
   mainProxy[0][0][0] = new MovieClip();
   mainProxy[0][0][0][0] = new MovieClip();
   mainProxy[0][0][0][0].name = "MC[0][0][0][0]";
   
   
   
   // 用 DisplayObjectProxy 取出四層之下的 Child
   trace(mainProxy[0][0][0][0].name);
   // MC[0][0][0][0]
   
   
   // 相較之下,AS3 正規方式相當複雜
   trace(
   (
    (
     (
      (
          this.getChildAt(0) as DisplayObjectContainer
      ).getChildAt(0) as DisplayObjectContainer
     ).getChildAt(0) as DisplayObjectContainer
    ).getChildAt(0) as DisplayObjectContainer
   ).name
   );
   // MC[0][0][0][0]
   
   
   
   // 用 DisplayObjectProxy 取出不存在的 Child 物件
   trace(mainProxy[0][0][0][2]);
   // null
   
   
   // 將 DisplayObjectProxy 脫殼
   trace(describeType(mainProxy[0][0][0][0].valueOf()).@name);
   // flash.display::MovieClip
   
   
  }
 }
 
}

相關連結:
AS3 DisplayObjectProxy 改版

Read more...

2007年10月20日星期六

用 Flash 開發 Flex Skin 才是王道   [+/-]

Ticore's Blog

日前 Adobe Labs 推出了許多外掛 Adobe Labs - Flex Skin Design Extensions
可以讓設計師容易使用 Flash、Photoshop、Illustrator、Fireworks 開發 Flex Skin
但是 Flex 原本就是 SWF Base 的東西
自然以 SWF 為來源,可以達到最好的效果
以下是四種軟體輸出 Flex Skin 功能比較:

時間軸
影格標籤
Tween 動畫
ActionScript
點陣圖
點陣圖
九宮格縮放
向量圖
向量圖
九宮格縮放
點陣圖柔化
Flash
Illustrator
×
×
×
×
Photoshop
×
×
×
×
×
Fireworks
×
×
×
×
×

由上表看來,使用 Flash 作為 Flex Skin 最後輸出工具才是最好選擇
這並不代表,其它三種軟體沒有用
因為 Flash 本身畫圖工具不夠,還是需要繪圖軟體輔助

相關連結:
兩種使用 Flash 開發 Flex Skin 方式比較
在 Flash 作點陣圖九宮格縮放技巧
Flex Embed 點陣圖檔小技巧

Read more...

2007年10月19日星期五

一行 AS3 程式讓 Flash Player 9 死機 Part 2   [+/-]

Ticore's Blog

繼之前『一行 AS3 程式讓 Flash Player 9 死機
沒想到還有機會推出 Part 2
死機程式的變化型還多出十幾種以上呢!
主要都是使用 RegExp 產生的死機狀況

這次死機狀況略有不同
執行之後,會發現 Flash Player 視窗根本跑不出來
然後 CPU 一直滿載
假如不關閉,它也不會出現 Scripting Timeout Error
一直消耗記憶體,才一分鐘就吃到 500 mb 左右
非得要到工作管理員關閉 Flash Player 不可

各種 RegExp 一行死機程式變化型:

" ".match(/(?<= )/g);
"a".match(/(?<=a)/g);
"".match(/(?<=$)/g);
"".match(/(?<=)/g);
"".match(/(?=)/g);
"".match(/(?)/g);
"".match(/(?:)/g);
"".match(/(?>)/g);
"".match(/()?/g);
"".match(/()/g);
"".match(/()()/g);
"".match(/(())/g);
"".match(/^/g);
"".match(/^^/g);
"".match(/$/g);
"".match(/$$/g);
"".match(/|/g);
"".match(/||/g);
"".match(/ /gx);

從上述程式,可以發現一些共通點
都是與 String.match、RegExp Global Flag 有關

這問題會發生在以下版本:
Flash Player 9.0.16.0
Flash Player 9.0.28.0
Flash Player 9.0.45.0
Flash Player 9.0.47.0

Flash Player 9.0.60.120 之後的版本已經修正

相關連結:
一行 AS3 程式讓 Flash Player 10 死機 Part 5
一行 AS3 程式讓 Flash Player 9 死機 Part 4
一行 AS3 程式讓 Flash Player 9 死機 Part 3
一行 AS3 程式讓 Flash Player 9 死機
用 @* 指定 Attributes 造成 Flash Player 9 Crash

Read more...

2007年10月17日星期三

AS3 - Inline 宣告 XMLList 物件方式   [+/-]

Ticore's Blog

ActionScript 3.0 支援 E4X 主要有 XML、XMLList
XML 物件可以用 Inline 宣告方式,非常方便
但是文件上並沒有提及 XMLList Inline 宣告方式
有的時候就不太方便

這是我在寫程式的時候,偶然發現直接宣告 XMLList 的方式

Inline Declare XMLList:

var xmlList:XMLList =
 <>
  <node name="Node 1">
  </node>
  <node name="Node 1">
  </node>
 </>;
trace(xmlList.length()); // 2
trace(xmlList[0].@name); // Node 1
trace(xmlList[1].@name); // Node 2

// Ticore's Blog - http://ticore.blogspot.com/

另一種宣告 XMLList 方式:

var xml:XMLList =
<xml>
 <node/>
 <node/>
</xml>.*;

trace(xml.toXMLString());

利用 add operator 組成 XMLList 方式:

var xmlList:XMLList = <xml><node/></xml> + <></>;
trace(xmlList.length()); // 1
trace(xmlList.toXMLString());

相關連結:
Flash CS3 jsfl 也支援 E4X, RegExp
AS3 E4X 互補方案 XPath
AS3 E4X - QName 相關操作
AS3 利用 QName 快速存取 Namespace Member
AS3 E4X - XML 節點包覆
AS3 E4X 資料取出與計算
AS3 E4X - XML 節點交換
AS3 E4X - 插入 XML 節點
AS3 E4X - 刪除 XML 節點
AS3 E4X Tip - 你拿到的是 XML or XMLList?
AS3 E4X 技巧 - 替 XML 添加 prototype fnuction
AS3 E4X - XML Attribute 相關操作
用 @* 指定 Attributes 造成 Flash Player 9 Crash
AS3 E4X - XML、XMLList 物件內子節點參考指定與複製
AS3 E4X - XML 物件比較
AS3 E4X - 相關類別與物件建立
AS2、AS3 基礎型別物件一致性
原來 Firefox 1.5 就已經開始支援 E4X

Read more...

解決 IE 無法安裝 Flash Player ActiveX Bug   [+/-]

Ticore's Blog

問題描述:

當安裝過 Adobe Flash Player 9.0.64.0 ActiveX 之後
就無法安裝其它版本的 Flash Player
即使直接用 Flash Player Uninstaller 移除也無效

錯誤訊息 1.

您正在嘗試安裝的 Adobe Flash Player 版本不是最新版。
請造訪 http://www.adobe.com/go/getflashplayer 以取得最新、最安全的版本。
The version of Adobe Flash Player ActiveX that you are trying to install
 is not the most current version.

錯誤訊息 2.

Error 1904.Module
C:\WINDOWS\system32\Macromed\Flash\FlDbg9d.ocx
failed to register. HRESULT -2147220473.
Contact your support personnel.

Error 1904.Module
C:\WINDOWS\system32\Macromed\Flash\Flash9d.ocx
failed to register. HRESULT -2147220473.
Contact your support personnel.

Error 1904.Module
C:\WINDOWS\system32\Macromed\Flash\Flash8c.ocx
failed to register. HRESULT -2147220473.
Contact your support personnel.

解決方式:

修改註冊碼,執行 regedit,找到以下位置:

[HKEY_LOCAL_MACHINE\SOFTWARE\Macromedia\FlashPlayer\SafeVersions]
"10.0"=dword:00160057
"6.0"=dword:00000058
"7.0"=dword:00000049
"8.0"=dword:0000002a
"9.0"=dword:009f0000

將 "9.0", "10.0" 的二進位資料刪除就好

後來發現最好的方式還是使用 Flash Player Uninstaller
執行 cmd 進入命令提示字元
切換到 uninstall_flash_player.exe 所在目錄
輸入並執行 "uninstall_flash_player.exe /clean"
這樣就可以完全清除 Flash 相關的註冊碼並反安裝 Flash Player ActiveX or Plugin

2009/06/27 補充
後來發現 Windows KB923789 安全性更新 會強迫安裝更新 Flash Player
另外 Kaspersky 2009 也會鎖住 Flash Player 安裝檔案
強迫使用者無法移除有安全更新過的 Flash Player
這雖然是好意,但是對 Developer 來說還是不方便
解決的方式也不難,反安裝之前,先把 Kaspersky 暫停一下就好了

相關連結:
Flash Player ActiveX 9.0.115.0 Upgrade Bug

Read more...

2007年10月9日星期二

Flex - 自動伸縮的 Tree   [+/-]

Ticore's Blog

Flex Tree 組件並沒有直接提供判定內容資料長度的方式
想要依據內容資料動態調整 Tree 高度就很不方便
以下透過繼承 Tree 方式,加入 autoStretch 屬性
讓 Tree 可以自動依據內容高度伸縮

AutoStretchTree Class:

package {
 import flash.events.*;
 import flash.utils.*;
 
 import mx.controls.Tree;
 import mx.events.TreeEvent;
 
 public class AutoStretchTree extends Tree {
  
  private var timer:Timer = new Timer(10, 1);
  private var _autoStretch_:Boolean = false;
  
  [Bindable]
  public function get autoStretch():Boolean{
   return _autoStretch_;
  }
  
  public function set autoStretch(value:Boolean):void{
   _autoStretch_ = value;
   if (_autoStretch_) {
    this.addEventListener(Event.RESIZE, doStretch);
    this.addEventListener(TreeEvent.ITEM_OPEN, startStretch);
    this.addEventListener(TreeEvent.ITEM_CLOSE, startStretch);
    this.verticalScrollPolicy = "off";
    stretch();
   } else {
    timer.stop();
    this.removeEventListener(Event.RESIZE, doStretch);
    this.removeEventListener(TreeEvent.ITEM_OPEN, startStretch);
    this.removeEventListener(TreeEvent.ITEM_CLOSE, startStretch);
    this.verticalScrollPolicy = "auto";
   }
  }
  
  protected function stretch(evtObj:Event = null):void{
   var items:Array = this.listItems;
   var borderThickness:Number = this.getStyle("borderThickness");
   
   if (this.height - borderThickness * 2 < this.rowHeight) {
    this.height = this.rowHeight + borderThickness * 2;
   }
   if (this.maxVerticalScrollPosition > 0) {
    this.height += this.rowHeight - (this.height - borderThickness * 2) % this.rowHeight;
    return;
   } else if (items[items.length - 1] == "") {
    this.height -= this.rowHeight + (this.height - borderThickness * 2) % this.rowHeight;
    return;
   }
  }
  
  protected function startStretch(evtObj:Event = null):void{
   timer.stop();
   timer.delay = this.getStyle("openDuration") + 50;
   timer.start();
  }
  
  protected function doStretch(evtObj:Event = null):void{
   timer.stop();
   timer.delay = 10;
   timer.start();
  }
  
  protected function onTimerComplete(evtObj:Event = null):void{
   stretch();
  }
  
  public function AutoStretchTree():void{
   super();
   timer.addEventListener(TimerEvent.TIMER_COMPLETE, onTimerComplete);
  }
  
 }
}

Flex MXML Code:

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
 layout="horizontal" horizontalScrollPolicy="off" backgroundColor="#FFFFFF">
 <mx:XMLList id="dataXML">
  <node label="Folder 1">
   <node label="Node 01" />
   <node label="Node 02" />
   <node label="Node 03" />
   <node label="Node 04" />
  </node>
  <node label="Folder 2">
   <node label="Folder 2-1">
    <node label="Node 01" />
    <node label="Node 02" />
    <node label="Node 03" />
    <node label="Node 04" />
   </node>
   <node label="Node 01" />
   <node label="Node 02" />
   <node label="Node 03" />
   <node label="Node 04" />
  </node>
  <node label="Folder 3">
   <node label="Folder 3-1">
    <node label="Node 01" />
    <node label="Node 02" />
    <node label="Node 03" />
    <node label="Node 04" />
   </node>
   <node label="Node 01" />
   <node label="Node 02" />
   <node label="Node 03" />
   <node label="Node 04" />
  </node>
  <node label="Folder 4">
   <node label="Folder 4-1">
    <node label="Node 01" />
    <node label="Node 02" />
    <node label="Node 03" />
    <node label="Node 04" />
   </node>
  </node>
  <node label="Node 01" />
 </mx:XMLList>
 <comp:AutoStretchTree xmlns:comp="*" width="100%"
  dataProvider="{dataXML}" labelField="@label" autoStretch="true">
 </comp:AutoStretchTree>
</mx:Application>
<!-- Ticore's Blog - http://ticore.blogspot.com/ -->

Online Demo:

相關連結:
Flex - Tab Tree

Read more...

2007年10月7日星期日

Flex DividedBox Skin 小技巧   [+/-]

Ticore's Blog

Flex 的 UIComponent 大多數可以設定樣式
但是 DividedBox 中的分隔線,並無可設定樣式屬性
也懶得自行去繼承修改樣式,所以想到以下的小技巧
使用 DataBinding 與額外的 UIComponent 拼出類似的效果

Flex MXML Code:

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
 layout="horizontal" width="400" height="300" backgroundColor="#FFFFFF">
 <mx:Script>
  <![CDATA[
   
   [Bindable]
   [Embed(source="../assets/DividerBox.png", scaleGridTop="3",
    scaleGridBottom="6", scaleGridLeft="3", scaleGridRight="6")]
   public var DividerBox:Class;
   
  ]]>
 </mx:Script>
 <mx:Container x="{box1.width + hDivBox.x + 1}" y="0" width="10" height="100%"
  mouseEnabled="false" mouseChildren="false"
  backgroundImage="{DividerBox}" backgroundSize="100%" />
  
 <mx:HDividedBox id="hDivBox" width="100%" height="100%" borderStyle="solid">
   
  <mx:Box id="box1" width="50%" height="100%" backgroundColor="#FFD0C0">
  </mx:Box>
  <mx:Box id="box2" width="50%" height="100%" backgroundColor="#C0D0FF">
  </mx:Box>
  
 </mx:HDividedBox>
 
</mx:Application>
<!-- Ticore's Blog - http://ticore.blogspot.com/ -->

Flex HDividedBox 範例擷圖:

相關連結:
Flex 技巧 - 緊密無縫的 DividedBox 2
Flex 技巧 - 緊密無縫的 DividedBox

Read more...

2007年10月6日星期六

在 Flash 作點陣圖九宮格縮放技巧   [+/-]

Ticore's Blog

Flash 8、9 雖然有支援 Scale 9 縮放功能
但是僅限於向量物件
MovieClip 的 Scale 9 設定對點陣圖並沒有效果
以下介紹一個技巧,可以讓 Flash Scale 9 功能也能應用在點陣圖上

先將點陣圖包成 MovieClip,並勾選 Scale 9 設定

將點陣圖打散成為向量填色區塊

沿著 Scale 9 Grid 劃線,將點陣圖填色區塊切割開

最後,把九個填色區塊個別包成群組,刪除切割用的線條
這樣該 MovieClip 便可以用 Scale 9 模式縮放了

Flash 點陣圖九宮格 (Scale 9) 縮放比較

相關連結:
Tween Effect & Scale 9 Grid Redraw Bug
ActionScript Scale9Grid 使用技巧
Flex Embed 點陣圖檔小技巧
用 Flash 開發 Flex Skin 才是王道

Read more...

Flex Embed 點陣圖檔小技巧   [+/-]

Ticore's Blog

Flex 可以使用 Embed 標籤,指定外部圖檔素材
但是透過這種方式匯入的圖片預設是無抗鋸齒效果的
雖然可以自行用 AS3 重新以 smooth 方式 draw
不過實在太麻煩

先看看直接 Embed 圖檔的情況,有很嚴重的鋸齒

以下介紹利用 Flash 改善點陣圖鋸齒

將圖檔匯入 Flash,並且勾選 Allow smoothing 選項

將圖片包成一個 MovieClip,並輸出 SWF
在 Flex MXML 內指定 Embed 標籤

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
 width="120" height="112"
 backgroundImage="@Embed(source='assets.swf', symbol='fx')">
</mx:Application>
<!-- Ticore's Blog - http://ticore.blogspot.com/ -->

執行結果

相關連結:
用 Flash 開發 Flex Skin 才是王道
在 Flash 作點陣圖九宮格縮放技巧
Flex Embed 外部資源技巧
AS3 - Flash CS3, CS4 點陣圖柔化輸出設定的臭蟲

Read more...

2007年10月2日星期二

AS2 UIComponent FocusRect 小技巧   [+/-]

Ticore's Blog

AS2 UIComponent 具有 Focus 外框功能
不過僅限於鍵盤 Focus 時候才會出現
只要一用滑鼠,淡綠色的 Focus 外框就會消失
以下介紹一個小技巧,hack FocusManager 行為
即使用滑鼠點到 UIComponent 或是 TextField,也會出現 Focus 外框

AS2 FocusManager Hack:

focusManager._onMouseDown = null;

var lisObj:Object = new Object();
lisObj.onSetFocus = function(o1:Object, o2:Object) {
 if (o2.drawFocus != null) {
  o2.drawFocus(true);
 }
};
Selection.addListener(lisObj);
// Ticore's Blog - http://ticore.blogspot.com/

效果擷圖:

相關連結:
Flash UIComponent 與 Button 混用焦點問題

Read more...

2007年10月1日星期一

Flash Player Debug 版本支援 System.gc();   [+/-]

Ticore's Blog

在測試 Flex 3 Profiling 時發現居然有執行 Garbage Collection 功能的按鈕
於是搜尋 Flex Builder 3 Beta 2 Help
找到 flash.system.System 有 gc 的 function 可用
不過只限於 debug 版本的 Flash Player and AIR

實際測試之後,原來這功能在前兩版就加入了
這些都是支援 System.gc(); 的版本
Flash Player Debug 9.0.60.120
Flash Player Debug 9.0.60.184
Flash Player Debug 9.0.60.235
.....

Read more...

FlashPlayer 9.0.60.325 改正 Function Closure GC Bug   [+/-]

Ticore's Blog

今天剛出 Flex Builder 3.0 beta 2
增加了許多功能~~
並且附帶了一個新版的 Flash Player 9.0.60.325
其中一個重要功能 Flex Profiling,可以觀察 Flash Player 記憶體變化與物件
敢出這樣的功能,想必一定是對 Flash Player GC Bug 做了修正

Flash Player 9.0.60.325

Flex Profiling

說實話,Flex Profiling 很難找到我要的物件~~
所以還是用之前的 Function Closure GC 測試程式來測

輸出結果:

count : 0   totalMemory : 2560000
count : 1   totalMemory : 2564096
index : 0
count : 2   totalMemory : 2564096
index : 0
index : 1
count : 3   totalMemory : 2572288
index : 0
index : 1
index : 2
count : 1   totalMemory : 2703360
index : 2365
count : 2   totalMemory : 2703360
index : 2365
index : 2366
count : 3   totalMemory : 2703360
index : 2365
index : 2366
index : 2367

Flash Player 9.0.60.325 果然改善了~!
index 為 0 的 Function Closure 不見了

相關連結:
ActionScript 3.0 - Function Closure GC Bug

Read more...

AS3 URLVariables 可以解析重複變數為陣列了   [+/-]

Ticore's Blog

AS2 LoadVars 在解析 Key-Value Pairs 資料時
遇到重複的變數名稱,只會保留最後一個值
不過 AS3 的 URLVariables 可以解析重複變數為陣列了~

測試程式:

import flash.net.*;
var str:String = "a=1&a=2&a=3";
var urlVar:URLVariables = new URLVariables();
urlVar.decode(str);
trace(urlVar.a); // 1,2,3
trace(urlVar.a[0]); // 1
trace(urlVar.a[1]); // 2
trace(urlVar.a[2]); // 3
// Ticore's Blog - http://ticore.blogspot.com/
Read more...