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

2010年8月18日 星期三

保護FMS上的影片內容,Protect video content (Flash Media Server)

基本的兩個方法:
  1. Verify SWF files
  2. RTMPE

Verify SWF files 設定(以windows為例)
  1. 於FMS底下找到[FMS資料夾]\conf\_defaultRoot_\Application.xml
  2. 找到標籤<SWFVerification enabled="false">將其改成<SWFVerification enabled="true"> ,這是啟動SWF驗證功能。
  3. 找到標籤<SWFFolder></SWFFolder>將其改成<SWFFolder>C:\Program Files\Adobe\SWFs</SWFFolder>,裡面的路徑放你自己容易管理的所在位置即可,官方文件上建議使用SWFs作為驗證資料夾名稱,這個資料夾是用來置放驗證的SWF,也就是當你建立一隻SWF檔之後,該SWF檔須複製一份於此資料夾,否則FMS部會允許該SWF檔連線,也就是不再驗證資料夾內的SWF檔都無法使用FMS資源。
使用RTMPE
  1. RTMPE在FMS中是預設啟用的。
  2. 找到標籤<DisallowedProtocols> </DisallowedProtocols>將其設成<DisallowedProtocols>rtmp,rtmps,rtmpt</DisallowedProtocols>,這行是說禁止使用rtmp、rtmps、rtmpt,也就是說只能使用rtmpe協定連線。

深入淺出JAVA,第一章,閱讀筆記

JAVA運作方式


  1. 編寫原始碼文件,原始碼文件以.java為附檔名。
  2. 編譯器編譯原始碼文件。
  3. 產出Bytecode檔案,經編譯產出的bytecode檔,以.class為附檔名。
  4. Virtual Machine讀取執行Bytecode檔。

Class與main
  • 每個Java程式中只能有一個main() Mathod,且每個程式至少都會有一個main與class。
  • 所有Java程式都是由main()開始執行。
public class Example
{
 public static void main(String[] args)
 {
  System.out.println("Hello World!");
 }
}


迴圈結構 while 、do-while 、for
  • 迴圈關鍵在於測試條件(conditional test),測試結果必定是boolean值,ture或false。
  • java的測試條件只接受boolean,若給予非boolean的值會編譯錯誤!與AS3很不同。
  
   int x = 2;
   while(x){}
  • 上述程式片段中,於JAVA中此x是整數,編譯時會發生錯誤,而在AS3中則會以非0值皆為true來運行,因為AS3具有隱含轉換。
條件式分支 if 、if else
int x = 3;
if(x == 3){
 System.out.println("x =3");
}

int value = 3;
if(value ==2){
 //條件測試結果為true時執行
 System.out.println("數值是2");
}else{
 //條件測試結果為false時執行
 System.out.println("數值不是2");
}

Flex3 Embed Font

Flex3中需Embed 字形才能讓文字做旋轉等效果,Flex4中似乎是不需要Embed就可以做出文字旋轉放大的效果,日後查明,先行紀錄Flex3 Embed Font用法。

Flex3中Embed Font

@font-face
{
 src:url("/fonts/MSJH.ttf");
 fontFamily:DIN;
 advancedAntiAliasing: true;
}
.embeddedFontStyle
{
 fontFamily:DIN;
 fontSize:18px;
 color:#CCCCFF;
}