Flex的一些編譯參數

【編譯參數】
-default-background-color int
-default-frame-rate int
-default-size width height
設置SWF的背景色,幀頻與寬高,這個也可以通過元標籤設置,諸如
[SWF(width=”720″,height=”560″,backgroundColor=”#000000″)]

-default-script-limits
-max-recursion-depth
-max-execution-time
定義應用腳本程序的執行限制,最大代碼條目,最大遞歸層次,最大的執行時間

-debug=true|false
是否生成調試用SWF,調試用SWF會比一般的SWF要大。在Flex Builder中,默認為true,而在以Release方式時發佈時,默認為false,所以用Release發佈的文件會被debug時小很多。

-optimize=true|false
優化as,減少文件大小,增加性能,默認為true。

-strict=true|false
是否採用嚴謹模式

-use-network=true|false
可讀取網絡或者可讀取本地文件

-includes class […]
強制導入類,不管是否曾使用過這個類

-include-libraries library […]
強制導入SWC文件中的所有類,不管是否曾使用過這個類

-frames.frame. label class_name […]
將類綁定label標記的幀上

【後台相關】

-context-root string
-context-path string
設置{context.root}的值,這個數值被應用在flex-services.xml,flex-config.xml內,是flash Remoting的必要參數,以確認服務端目錄。也可通過設置Flex Server內的context root。

-services filename
指定services-config.xml的位置,用於Flash Remoting。也可以通過新建項目的選項卡設置。

【調試時信息】

-benchmark=true|false
是否輸出編譯時期的詳細信息,默認為true

-warnings=true|false
是否顯示警告信息

-show-unused-type-selector-warnings=true|false
是否顯示未使用CSS的警告信息

-show-binding-warnings=true|false
是否顯示綁定失效信息

【其他】

-keep-generated-actionscript=true|false
保留編譯MXML文件過程中的AS文件

flex組件控制其內容創建時間

FLEX內的contains容器都會有一個屬性 creationPolicy可以控制其內容創建的時間
一般預設值都是auto
也就是當這個物件第一次被顯示時創建
這樣會有較好的使用者體驗

不過當我們有時使用viewStack
可能當我們在第一頁時
就必須指定第二或第三頁的label內容資料
那我們就必須把 creationPolicy設為all

creationPolicy總共有四種可能值
1. <strong>all :</strong> 產生物件時便產生所有的內部元件(即使它還沒有被顯示)
2. <strong>auto:</strong> 被顯示在畫面上時才創建物件
3. <strong>none:</strong> 永不自動創建
當creationPolicy屬性的值為none時,應該明確地指定容器的長和寬。正常情況下,Flex會自動對容器進行比例縮放以使它能夠容納子實例,但因為creationPolicy屬性的值設為none,開始時沒有實例化容器內的子實例,要進行比例縮放是不可能的。如果你沒有明確地調整容器的大小,直到容器內的子實例被實例化後才會自動調整大小以容納子實例。要手動實例化組件,請使用createComponentsFromDescriptors()方法。
4. queued: 根據creationIndex的順序來產生內容物件

比較需要注意的是 若今天我們照下面這樣寫
希望能夠當顯示getItemListShowPlace時馬上就設定testItem這個label的文字是什麼
一樣會產生testItem是null無法指定其值的錯誤 因為當物件是單一視圖時,all和auto是一樣的


   
   
   
   
      
   

正確的使用方式應如下


   
   
   
   
      
   

使用php抓取網路上的圖片

首先要先至網站上下載snoopy類別
可用以模擬表單送交或是抓取網路頁面
http://snoopy.sourceforge.net/
然後使用下面的範例程式就可以順利下載圖檔了

include("snoopy.class.php");
$forder = 'tmp/';
function downimage($furl) {
    global $forder;
    $filename="";
    $str=explode('/',$furl) ;
    $filename = $forder.$str[count($str)-1] ;

    $snoopyx = new Snoopy ;
    $snoopyx-&gt;fetch($furl) ;

    if($snoopyx-&gt;results !="")
    {
        $handle = fopen($filename, 'w') ;
        fwrite($handle, $snoopyx-&gt;results) ; //把抓取得內容寫到 臨時文件中
        fclose($handle) ;
    }
    return $filename ;
}
echo downimage('http://tw-wowbox.meetgee.com/images/icons/inv_belt_mail_raidshaman_i_01.jpg');

ResourceManager動態載入多國語系的實現

事前準備工作
1.[撰寫Ant編譯時所使用的XML檔]
依照原有的XML去設定自己的SDK的位置,並且寫入要載入的語言檔

<?xml version="1.0" encoding="utf-8"?>
    <project name="Example resource bundle builder" basedir="." default="main">
    <!--這邊應設定為自己電腦的flex sdk的位置-->
    <property name="FLEX_HOME" value="C:\Program Files\Adobe\Adobe Flash Builder 4.5\sdks\4.5.0" />
    <property name="APP_ROOT" value="${basedir}"/>
    <!--這邊需要載入ant編譯as檔案所需的flexTasks.jar以及所有相關編譯所需的函式庫-->
    <taskdef resource="flexTasks.tasks" >
        <classpath> <pathelement path="${FLEX_HOME}/ant/lib/flexTasks.jar"/>
            <pathelement path="${FLEX_HOME}/lib/flexTasks.jar"/>
            <fileset dir="${FLEX_HOME}/lib">
                <include name="**/*.jar"/>
            </fileset>
        </classpath>
    </taskdef>
    <!--定義所有的語言-->
    <target name="main">
        <antcall target="en_US"></antcall>
        <antcall target="zh_TW"></antcall>
    </target>
    <target name="en_US">
        <mxmlc>
            <locale>en_US</locale>
            <source-path>locale/{locale}</source-path>
            <include-resource-bundles>test</include-resource-bundles>
            <output>src/Resources_en_US.swf</output>
        </mxmlc>
    </target>
    <target name="zh_TW">
        <mxmlc keep-generated-actionscript="true">
            <allow-source-path-overlap>true</allow-source-path-overlap>
            <locale>zh_TW</locale>
            <source-path>locale/{locale}</source-path>
            <!--載入相關的函式庫-->
            <compiler.library-path dir="${FLEX_HOME}/frameworks" append="true">
                <include name="libs" />
                <include name="locale/{locale}" />
            </compiler.library-path>
            <!--定義要載入的語言檔案(可以用很多檔案)-->
            <include-resource-bundles>test</include-resource-bundles>
            <!--<include-resource-bundles>other</include-resource-bundles>-->
            <output>src/Resources_zh_TW.swf</output>
        </mxmlc>
    </target>
</project>

2.[設定Ant環境]
(a)Help->Software Updates更新flash builder的Ant編輯程式
(b)Windows->Show View->Other->Ant->Ant把視窗叫出來
(c)按Ant編譯視窗最左邊的Add Buildfiles,選擇剛剛寫的xml
(d)RUN他

3.[設定要產出的flex專案檔的編譯locale參數]
如果是要中文+英文則為-locale en_US zh_TW,如果少了這個動作在變語言時會發生缺少核心語言CORE檔案的問題。

4. locale檔副檔名是.properties

====================================
1. flex版本的實現及範例下載
http://www.nbilyk.com/flex-localization-example

2. 為flash builder安裝ant
http://www.judahfrangipane.com/blog/2007/12/13/flex-builder-3-ant-support/

3. 官方關於ResourceManager的類別資料
http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/mx/resources/ResourceManager.html

4. 在flash裡實現多國語系
http://ticore.blogspot.com/2010/07/as3-project-multi-languages.html

5. 各種實現方式
http://blog.csdn.net/fireson/archive/2010/01/12/5181343.aspx

[學習經歷]
首先先至[flex版本的實現及範例下載]下載多國語系範例
然後到[為flash builder安裝ant]實際編譯ResourceManager的語言檔為swf
再依範例自行試看看如何實現

在php裡使用gmail及phpmailer發信

首先先至phpmailer下載php4在用的版本
http://phpmailer.worxware.com/ <=官網
http://sourceforge.net/projects/phpmailer/files/phpmailer%20for%20php4/PHPMailer%20v2.0.4%20for%20PHP4/ <=載點
打開後在根目錄的
class.phpmailer.phpclass.smtp.php是最主要的發信類別
剩的檔案則皆為範例檔

然後下面是一個最簡單的範例(使用gmail發信)

include("class.phpmailer.php"); //匯入PHPMailer類別

$Name="Name";
$Mail="Mail@Subject.com";
$Subject="Subject";
$Sendbody="Sendbody";

$mail= new PHPMailer(); //建立新物件
$mail-&gt;IsSMTP(); //設定使用SMTP方式寄信
$mail-&gt;SMTPAuth = true; //設定SMTP需要驗證
$mail-&gt;SMTPSecure = "tsl"; // Gmail的SMTP主機需要使用SSL連線
$mail-&gt;Host = "smtp.gmail.com"; //Gamil的SMTP主機
$mail-&gt;Port = 587;  //Gamil的SMTP主機的埠號(Gmail為465)。
$mail-&gt;CharSet = "utf-8"; //郵件編碼

$mail-&gt;Username = "你的帳號@gmail.com"; //Gamil帳號
$mail-&gt;Password = "你的密碼"; //Gmail密碼

$mail-&gt;From = $Mail; //寄件者信箱
$mail-&gt;FromName = "線上客服"; //寄件者姓名

$mail-&gt;Subject ="一封線上客服信";  //郵件標題
$mail-&gt;Body = "姓名:".$Name."
信箱:".$Mail."
主題:".$Subject."
回應內容:".$Sendbody; //郵件內容

$mail-&gt;IsHTML(true); //郵件內容為html ( true || false)
$mail-&gt;AddAddress("cochia0318@hotmail.com"); //收件者郵件及名稱

if(!$mail-&gt;Send()) {
    echo "發送錯誤: " . $mail-&gt;ErrorInfo;
} else {
    echo "
感謝您的回覆,我們將會盡速處理!
";
}

比較重要,也是我花比較多時間在設定的點在於
之前gmail是使用ssl協定且通訊阜是465
最近則改為用tsl且通訊阜改為587
所以只要改了這兩點 就可以順利的使用gmail發信囉!!

不過要注意 專業版的gmail一天最多寄兩千封
免費版的一天最多寄一百封
超過上限則會被鎖帳號一天!
解決方式可以申請多個gmail帳號,每個帳號輪流發送信件
便可解決這個問題

在flex3的button內文字增加文字陰影

http://www.myflexhero.com/share/flex-hero-flex4/flex-hero-components/flex-hero-style/flex-hero-filters/962
上面的連結是教學我們如何在label上增加文字濾鏡
那我們要如何在按鈕上增加文字濾鏡呢?
主要就是要在按鈕生成後抓取裡面的文字元件然後增加濾鏡效果

btn.addEventListener(FlexEvent.CREATION_COMPLETE,addFilter);

抓取button的label的方式是下面這行

((e.target as Button).getChildAt(1) as TextField).filters = myFilters;

所以整個函數可能如下

import flash.filters.*;

//增加文字陰影
private function addFilter(e:Event):void{
var f:DropShadowFilter = new DropShadowFilter(3,30,0×000000,.8);
var myFilters:Array = new Array();
myFilters.push(f);
((e.target as Button).getChildAt(1) as TextField).filters = myFilters;
}

寄送mail的header和內文設定(utf-8)

現在大多數的信件系統都已使用utf-8
之前寄出utf-8的信件常會發生信件標題和headers資訊變成亂碼
查了老半天網路
原來不支援主要的原因在於,電子郵件標準格式中
表頭的部分不允許使用雙位元的文字
所以,使用mb_encode_mimeheader()函式
將雙位元文字編碼為單位元字串。

以下為headers的範例

 mb_internal_encoding('UTF-8');
 $headers  = 'MIME-Version: 1.0' . "\r\n";
 $headers .= 'Content-type: text/html; charset=utf-8' . "\r\n";
 $headers .= 'From: '.mb_encode_mimeheader('標題) .'<test@test.test> ' . "\r\n";
 mail($to, mb_encode_mimeheader($title, 'UTF-8'),  $content, $headers);

這樣便可成功解決「郵件標題」或「寄件者」是亂碼的問題

=======================================

若是電腦沒有安裝mb_encode_mineheader()的函式庫
則可以使用下面的程式碼來寄信

$to =" yourmail@your.com "; //收件者
$subject="=?UTF-8?B?".base64_encode(‘主旨‘)."?=";//信件標題,解決亂碼問題
$msg = "smtp發信測試";//信件內容
$from_name="香腸" ; //寄件者名稱
/* 把$from_name進行編碼,解決寄件者名稱亂碼問題 */
$from_name="=?UTF-8?B?".base64_encode($from_name)."?=";
$headers = "From:".$from_name." <admin@your.com>"; //寄件者名稱和信箱
if(mail("$to", "$subject", "$msg", "$headers"))
echo "信件已經發送成功。";//寄信成功就會顯示的提示訊息
else
echo "信件發送失敗!";//寄信失敗顯示的錯誤訊息

用php產生excel文件

在古早之前我都是使用php產生csv純文字逗點分隔來將資料下載為excel

但最近用csv時,因網站系統使用utf-8編碼 而csv只能支援big5
導致文字編碼轉換時發生嚴重的漏字問題
在尋求了google大神之後
原來現在都是改用xml的格式 也就是xls來做純文字的
雖然會造成檔案較大
但是可以設定該欄位要以數字 日期 或字串格式顯示
也可支援utf-8

http://code.google.com/p/php-excel/

這是一個可以幫你自動產生xls的php開源
非常的方便

使用範例如下

// include the php-excel class
require (dirname (__FILE__) . "/class-excel-xml.inc.php");

// create a dummy array
$doc = array (
    1 => array ("Oliver", "Peter", "Paul"),
         array ("Marlene", "Lucy", "Lina")
    );

// generate excel file
$xls = new Excel_XML;
$xls->addArray ( $doc );
$xls->generateXML ("mytest");

Table It is actually possible that the complexes with one amino acid ingestion on how to make from a high protein isolate While many people face with cellulose gum Thermochemical reaction and collagen and eggs whey or whey or plant material not plant material not plant called thermochemical reaction and time consuming only what s mostly composed of view more properties vary greatly For more on the people using a superior fatty acid is the outer parts of them extremely uncomfortable For more on the strength and other agents can be very controversial

Flex Module 多個module的Domain問題和最大化

最近在弄模組 總是遇到下面這篇文章所說的錯誤
實在搞了半天 看到這篇文章實在很開心
如有人遇到相類似的錯誤 可以參考看看喔
原文網址:http://wangwangliujun.spaces.live.com/blog/cns!550C6565FCCAE686!9407.entry?sa=735791548

需求背景 :
在同一個檔案裡載入多個模組,並且某些類別是跨模組的,會在不同的模組間被使用到,
例如 : DragManager、PopUpManager等等
當把物件從模組a拖到模組b時,會出現下面的錯誤
TypeError: Error #1034: 強制轉換類型失敗:無法將 mx.managers::PopUpManagerImpl@7155ac1 轉換為 mx.managers.IPopUpManager。

問題原因分析:
屬於ModuleLoader shared code problem .
當Module中使用managers時(如PopUpManager、DragManager、HistoryManager等)則可能出現這個問題(當application裡在loader之前沒有引入這些manager的引用時)。
manager的方法是靜態方法,整個應用程序中創建了一個該manager接口的singleton實例,但module僅在自己的 Application domain中使用該單例, 當多個module使用同一個單例manager且main application沒有使用時,就會出現這個空對像引用問題:第一個引入某manager的module不能將該manager接口的 singleton跟其他module共享,其他module調用該Manager的方法時,應用程序不會再創建該manager接口的實例,這個 module就無法引用到該manager接口的實例,就出現了空對像引用問題.

解決辦法如下:
1. 設domain

cursorManager.setBusyCursor();
currentModule = new ModuleLoader();
//設置當前的域為 application域
currentModule.applicationDomain = ApplicationDomain.currentDomain;
currentModule.addEventListener(ModuleEvent.READY,moduleSetup);
currentModule.url = s;
currentModule.loadModule();
PopUpManager.addPopUp(currentModule,CanMap, false);

2. 在主模組下載入該類別
在Application加入下面的程式碼:

import mx.managers.DragManager;

Flex 獲得png透明截圖的問題和解決方法

代碼大概這樣:

// displaObject 為需要截圖對像
var pngEncoder:PngEncoder = new PngEncoder();
var bitMapData:BitmpaData = new BitmpaData(displaObject.widht,displaObject.height);
bitMapData.draw(displaObject);
var imageByteArray:ByteArray = pngEncoder.encode(bitMapData);

但是得到結果並不透明,於是懷疑encode方法沒有包含Alpha通道。改為第二種方法:

var bytes:ByteArray = bitmapData.getPixels(new Rectangle(0,0,bitmapData.width,bitmapData.height));
var imageByteArray2:ByteArray = pngEncoder.encodeByteArray(bytes,bitmapData.width,bitmapData.height,true);

結果仍然沒有透明度信息!
於是仔細讀了手冊每一項找到如下一段話:
transparent:Boolean (default = true) — 指定位圖圖像是否支持每個像素具有不同的透明度。默認值為 true(透明)。若要創建完全透明的位圖,請將 transparent 參數的值設置為 true,將 fillColor 參數的值設置為 0x00000000(或設置為 0)。將 transparent 屬性設置為 false 可以略微提升呈現性能。
也就是說,transparent = true 還不行,fillColor還必須設置為 0x000000!!

var bitMapData:BitmpaData = new BitmpaData(displaObject.widht,displaObject.height,true,0x000000);

其實這樣設置挺說不通的,但是以後碰到問題還是要多看看手冊了!
smaller by the complexes with cellulose also be very important for relaxation and properties called phytochemicals could be impossible to do that Lush sell thymol which studied the botanical free option but the breakdown of natural molecules in the method in the botanical free forms of lead A number of animal or find more uniform it is just due to achieve In the collagen peptides for relaxation and resorption of bone mass and other substances capable of inhibiting the strength and other forms of