2010年9月8日 星期三

Ubuntu 10.04 install Java6 (apt)

Ubuntu 10.04是預設是使用open java,如果要程式開發還是需要安裝Sun Java,以下是Ubuntu環境安裝Java6的過程記錄。

Step1.
sudo add-apt-repository "deb http://archive.canonical.com/ubuntu lucid partner"

這一行其實就是編輯了apt裡的sources.list
sources.list path
/etc/apt/sources.list

利用文字編輯器打開sources.list,拉到最下方,可以看到sources.list裡面被加入了
"deb http://archive.canonical.com/ubuntu lucid partner"




Step2.更新套件
  • sudo apt-get update
Step3.安裝java jre
  • sudo apt-get install sun-java6-jre sun-java6-plugin
Step4.安裝java jdk
  • sudo apt-get install sun-java6-jdk sun-java6-plugin
Step5.查詢java jdk版本
  • java -version


參考資料
ubunt社群
http://wiki.ubuntu.org.cn/index.php?title=Sun-java6&variant=zh-tw

IT開發者Blog
http://www.dotblogs.com.tw/bowwowxx/archive/2010/06/11/15794.aspx
http://hi.baidu.com/xlmeng1988/blog/item/2dce52ae73ef26f3faed50d2.html
http://askcuix.javaeye.com/blog/178819

2010年8月20日 星期五

Deprecated metadata tag



用法:
[Deprecated("string_describing_deprecation")]
[Deprecated(message="string_describing_deprecation")]
[Deprecated(replacement="string_specifying_replacement")]
[Deprecated(replacement="string_specifying_replacement", since="version_of_replacement")]

原文(引用自adobe flex4 help):
A class or class element marked as deprecated is one which is considered obsolete, and whose use is discouraged in the current release. While the class or class element still works, its use can generate compiler warnings

一個類別或是類別中的項目被標記成Deprecated表示此項目是過時的、廢棄的、不建議使用的,不鼓勵使用在當前的釋出版本。雖然被宣告廢棄的Class或Class中的項目仍然工作,但能讓編譯器產生警告提醒。

The mxmlc command-line compiler supports the show-deprecation-warnings compiler option, which, when true, configures the compiler to issue deprecation warnings when your application uses deprecated elements. The default value is true.

Insert the [Deprecated] metadata tag before a property, method, or class definition to mark that element as deprecated. The [Deprecated] metadata tag has the following options for its syntax when used with a class, property or method:
 
功用:

  • 標記已經廢棄的Class以免誤用,若使用編譯器會出現警告提醒。
範例:
//宣告method已經廢棄,並提示改用建議的method
package com
{
 import spark.components.Group;
 public class MyDeprecatedGroup extends Group
 {
  public function MyDeprecatedGroup()
  {
   super();
  }  
  private var _topGap:Number; 
  //宣告topGap廢棄,並建議使用topPixels
  [Deprecated(replacement="MyDeprecatedGroup.topPixels")] 
  public function set topGap(value:Number):void
  {
   _topGap = value;
  }
  public function get topGap():Number
  {
   return _topGap;
  }
 }
}  
//Application
<?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="application1_applicationCompleteHandler(event)" xmlns:com="com.*"
>
<fx:Script\>
<![CDATA[ 
]]>
</fx:Script>
<com:MyDeprecatedGroup>
 <com:topGap>1.0</com:topGap>  
</com:MyDeprecatedGroup>
</s:Application>   
訊息警告如下圖:
 
 
 
 
 
 

  • Event,Effect,Style,metadata tags也支援 deprecation功能

文件
The [Event], [Effect] and [Style] metadata tags also support deprecation. These tags support the following options for syntax:
 
在Event,Effect,Style的metadata tags中,也都支持deprecation的宣告,用法如下
 
用法
[Event(... , deprecatedMessage="string_describing_deprecation")]
[Event(... , deprecatedReplacement="change2")]
[Event(... , deprecatedReplacement="string_specifying_replacement", deprecatedSince="version_of_replacement")]

DefaultProperty metadata tag


用法:
[DefaultProperty("propertyName")]

原文:
The [DefaultProperty] metadata tag defines the name of the default property of the component when you use the component in an MXML file.

功用說明:
[DefaultProperty]標籤用來定義組件中的預設屬性,對應於MXML標籤檔上使用。

範例:
//這個範例將預設屬性改成selected,原本在toggleButtong上的預設屬性是label。
//myButton.as
package com
{

 import spark.components.ToggleButton;

 [DefaultProperty("selected")]
 public class myButton extends ToggleButton
 {
  public function myButton()
  {
   super();
  }
//mxml設定進來的值在此可以抓到並處理
  override public function set selected(value:Boolean):void
  {
   if(value != super.selected)
   super.selected = value;
  } 

 }

}
//mxml檔中使用ToggleButton與myButton來驗證結果
<s:Group layout="{new VerticalLayout()}">
<s:ToggleButton>true</s:ToggleButton> //預設屬性是label因此會出現true
<com:myButton>true</com:myButton>     //預設屬性是selected因此出現按下
</s:Group>












例外使用的狀況:
The one place where Flex prohibits the use of a default property is when you use the ActionScript class as the root tag of an MXML component. In this situation, you must use child tags to define the property, as the following example shows

主要是說,若是mxml做為根標籤,就無法直接在標籤中輸入文字使用預設值,而是須將改預設值名稱當成mxml標籤來呼叫使用。

當然這就是在說將Class做成mxml組件檔時的情境,範例如下:
//myButtonC.mxml
<?xml version="1.0" encoding="utf-8"?>
<com:myButton xmlns:fx="http://ns.adobe.com/mxml/2009" 
xmlns:s="library://ns.adobe.com/flex/spark" 
xmlns:mx="library://ns.adobe.com/flex/mx" xmlns:com="com.*">
<!--當成root標籤使用時,預設屬性設定改用標籤呼叫設定。-->
 <com:selected>true</com:selected>
</com:myButton> 

而這個組件放於Application上時,依然可以直接設定預設值如下:
<?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"
xmlns:com="com.*"
> 
<fx:Script>
<![CDATA[ 
import spark.layouts.VerticalLayout;
]]>
</fx:Script>
<s:Group layout="{new VerticalLayout()}">
<com:myButtonC>true</com:myButtonC>
</s:Group>
</s:Application>


參考
http://help.adobe.com/zh_CN/flex/using/WS2db454920e96a9e51e63e3d11c0bf680e1-7ffe.html

//查詢Creating a default property
http://help.adobe.com/zh_CN/flex/using/WS2db454920e96a9e51e63e3d11c0bf69084-79f7.html#WS2db454920e96a9e51e63e3d11c0bf69084-79fa

英文原文引用自adobe flex4 help文件

2010年8月19日 星期四

ArrayElementType Metadata tag


原文:
Using Flex4說明手冊中關於ArrayElementType的說明:
When you define an Array variable in ActionScript, you specify Array as the data type of the variable. However, you cannot specify the data type of the elements of the Array.

當你於ActionScript中定義一個Array變數,你指定Array為資料型態,然而你無法指定Array內項目的資料型態。
(在AS3中Vector可以指定陣列中項目的資料型態,Array本身沒有此項功能)

功用:
To allow the Flex MXML compiler to perform type checking on Array elements, you can use the [ArrayElementType] metadata tag to specify the allowed data type of the Array elements, as the following example shows:

你可以藉由ArrayElementType這個metadata tag讓MXML compiler來檢查Array的項目元素是否為ArrayElementType指定資料格式的項目。

使用範例:
//Class
package com
{ 
 import spark.components.Group;
 public class myGroup extends Group
 {
  public function myGroup()
  {
   super(); 
  } 
  //標籤宣告
  [ArrayElementType("Number")]
  public var myArray:Array; 
 }
}

//mxml檔案中
<com:myGroup id="mg">
<com:myArray>
<fx:int>1.0</fx:int>   //此處會有編譯錯誤警告,因為使用<int>
</com:myArray>
</com:myGroup>   
note:
在mxml中若是對myArray使用非Number的項目就會出像錯誤警告,但是此項功能僅對於MXML標籤有作用,若你使用ActionScript來對myArray來操作,並加入非Number資料型態的項目並不會出像編譯警告。
  •  ArrayElementType("Number")]的宣告對ActionScript直接操作是無效的
//在application Complete事件發生後去操作myArray,並給予非Number的項目,是可以通過編譯的
protected function application1_applicationCompleteHandler(event:FlexEvent):void 
{
 mg.myArray.push( "test" );
}

Flex顯示元件as與mxml之間轉換關係與其繼承實現方式

Flex比較有趣的地方就是顯示組件的.mxml與.as之間觀念轉換,假設我們要繼承一個Button,新的類別名稱為mybutton,置放於package com中,那麼.as檔架構的Class程式碼會如下

package com
{
 import spark.components.Button;
 public class myButton extends Button
 {
  public function myButton()
  {
   super();
  }
  //Override inherited method and properties.
  //Define new method and properties.
  //Custom logic in ActionScript.
 }
}
 

The Flex class hierarchy

Using Flex 章節About custom components

The Flex class hierarchy

 
All visual components are derived from the UIComponent ActionScript class. Flex nonvisual components are also implemented as a class hierarchy in ActionScript. The most commonly used nonvisual classes are the Validator, Formatter, and Effect base classes.


這段文章指出了Flex所有的視覺組件都是以UIComponent為父類,也是Flex開發中所有直接放於畫面上的顯示元件都必須繼承了UIComponent,那麼Flash所使用的顯示元件要如何放於畫面上,就是透由UIComponent來做,將Flash的顯示元件加入UIComponent即可。


如:

Flex set JVM help size

§Flex設定JVM 堆積區大小

在Using Flex4說明文件中提到
The compilers use the Java JRE. As a result, you can also configure settings such as memory allocation and source path with the JVM arguments.


Flex的編譯器需使用JVM來運作,因此,你也可以以設定記憶體配置與源路徑參數用於JVM上。

該設定檔名為jvm.config,該檔位於SDK中的bin底下,如win7會像是
C:\Program Files (x86)\Adobe\Adobe Flash Builder 4\sdks\4.1\bin\jvm.config