2011年5月25日 星期三

Alternative metadata tag


原文引用自Adobe Flex4.5_help手冊:
原文:

If you want to replace one class with another, mark the class to be replaced with the  [Alternative]  metadata tag. The
[Alternative]  metadata tag specifies the replacement class, and a version number that indicates when the
replacement occurred.

功用說明:
[Alternative]這個metadata標籤用於建議替代的類別與版本,如mx的Button會出現建議使用spark的Button,而在FlashBulider選用Class時可以看到如下圖訊息。










使用範例:
//舊的Cat Class
package com.jef
{
 [Alternative(replacement="com.jt.Cat", since="1.0")]
 /***/ //使用asDoc的註解,說明的asDoc才會出現
 public class Cat
 {
  public function Cat()
  {
  }
 }
}

//新的Cat Class
package com.jt
{
 public class Cat
 {
  public function Cat()
  {
  }
 }
}

//Flex mxml
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
      xmlns:s="library://ns.adobe.com/flex/spark" 
      xmlns:mx="library://ns.adobe.com/flex/mx" 
      minWidth="955" minHeight="600"
      applicationComplete="completeHandler(event)"
      >
 <fx:Script>
  <![CDATA[
   import com.jef.Cat;   
   import mx.events.FlexEvent;   
   protected function completeHandler(event:FlexEvent):void
   { 
    var cat:Cat;
   }   
  ]]>
 </fx:Script> 
</s:Application>

出現提示如下:










Alternative與Deprecated不同,Alternative原本的Class還可使用,只是有更新版本建議使用,而Deprecated則是說明該Class已經廢棄不要再使用。