Monday, March 22, 2010
Monday, March 15, 2010
Thursday, March 4, 2010
Wednesday, February 10, 2010
Calling Flash Remote Service in Flash with Zend amf
Steps:
- Download Zend amf library and put it into your htdocs (www root) folder.
- Create a Gateway.php for connection
- Create your service using php
- Connect to service using ActionScript in TestService.fla
- Run the TestService.fla
Step 1:
- Download Zend amf library: http://framework.zend.com/download/amf
- Unzip and put the Zend folder into your htdocs folder
Step 2:
- Create a folder named “service” under htdocs.
- Create a Gateway.php under htdocs.
- Gateway.php:
<?phprequire('./Zend/Amf/Server.php');//require('./services/HowAreYou.php');$server = new Zend_Amf_Server();$server->addDirectory(dirname(__FILE__) .'/services/');//$server->setClass('HowAreYou');$response = $server->handle();echo $response;?>
Step 3:
- Create your remote service “HowAreYou.php” under “service” folder
- HowAreYou.php
<?phpclass HowAreYou{/** @param string $receiveMsg* @return string $replyMsg*/function sendStr($yourname){return "$yourname, 你好!";}}?>
Step 4:
- Write ActionScript in your TestService.fla file
- In TestService.fla
stop();var connection:NetConnection; // Initialize NetConnection Objectvar responder:Responder; // Initialize Responder Object//Construct Instanceresponder = new Responder(onResult, onFault); // Show Receive Dataconnection = new NetConnection;// Settingvar gateway:String = "http://localhost/Gateway.php";connection.connect(gateway); // Connect to Zend amf// Data Receievefunction onResult(Result:String):void {trace(Result);}// Failfunction onFault():void {trace("Connection Fail");}// Call Remoting Service's Method: (Class.Method, reaonder, parameter)connection.call("HowAreYou.sendStr",responder,"your_message");
Step 5:
- Test(Run) your TestService.fla
- you will receive “your_message,你好!” on the output window
Tuesday, February 9, 2010
解決 amfphp 中文字串亂碼問題
In your htdocs\amfphp\gateway.php
Comment this line of code:
//$gateway->setCharsetHandler("utf8_decode", "ISO-8859-1", "ISO-8859-1");
Add this line of code:
$gateway->setCharsetHandler( "utf8_decode", "UTF-8", "UTF-8" );
Wednesday, November 18, 2009
Monday, September 21, 2009
How to include .swc file into Flash CS4 project?
- Open the "Publish Settings" window (File->Publish Settings)
- Press the "Settings…" button right to the item "Script:"
- Select "Library path" tab and then you can include your .swc file or the folder contain the .swc file
Saturday, August 29, 2009
ActionScript 3.0 Tutorial Slide. Hope it helps
I use this slide to give an ActionScript 3.0 Tutorial in the freshman training course of Intelligent Agent Laboratory in Department of Computer Science and Information Engineering of National Taiwan University.
FYI.
Coding Flash : ActionScript(3.0) TutorialView more documents from PEI-YAO HUNG.
Saturday, July 18, 2009
Produce Random Number with ActionScript
var randomNumber:Number;
randomNumber = Math.random(); // 0 <= randomNumber < 1
Catch Keyboard Event (Key Down) with ActionScript
// catch Key Down Event
stage.addEventListener( KeyboardEvent.KEY_DOWN, KeyDownEventHandler);
function KeyDownEventHandler(e:KeyboardEvent ){
trace(e.charCode);
trace(e.keyCode);
if( e.keyCode == Keyboard.UP){
// use keyCode to detect special key
}
else if( e.keyCode == Keyboard.DOWN){
}
else if( e.keyCode == Keyboard.LEFT){
}
else if( e.keyCode == Keyboard.RIGHT){
}
else if( e.keyCode == Keyboard.SPACE){
}
else if( e.keyCode == Keyboard.SHIFT){
}
else if( e.charCode == 98){
// b, ascii code = 98
// use charCode to detect character
}
else if( e.charCode == 108){
// l
}
else if( e.charCode == 97){
// a
}
else if( e.charCode == 65){
// A
}
else if( e.charCode == 118){
// v
}
else if( e.charCode == 114){
// r
}
else{
//
}
}
Monday, June 29, 2009
Using Global Variable in Flex
1. Declare the global variable in the main .mxml file.
In the main .mxml file :
<?xml version="1.0" encoding="utf-8"?>
<mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="TryAS()">
<mx:Script>
<![CDATA[
public var bookSize:Rectangle = new Rectangle(0,0,800,600);
public function TryAS():void{
trace("Hello World");
}
]]>
</mx:Script>
</mx:WindowedApplication>
2.Use Application.application.yourGlobalVariableName to access the variable.
In the .as class you write :
import mx.core.Application;
// Application.application.yourGlobalVariableName
Application.application.bookSize.width
Thursday, June 25, 2009
Writing Action Script in Flex
Writing Action Script in Flex
Example of a .mxml file :
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="TryAS()">
<mx:Script>
<![CDATA[
import Puzzles.*;
public function TryAS():void{
trace("InitPuzzles");
}
]]>
</mx:Script>
</mx:Application>
Sunday, December 9, 2007
MDM + as3corelib : 存檔寫 log (文字檔 + 圖檔)
// MDM Version (http://www.multidmedia.com/)
// encoder from as3corelib (http://code.google.com/p/as3corelib/)
/*
如果你要它存 PNG 結果掛掉的話,有可能是因為 轉成 png 以後太大了
(記憶體佔用太多,血淋淋的經驗,死的不明不白,完全看不出來為什麼4 張只存了一張以後好像就沒動靜了)
可以先改用 JPG 存檔並調整他的壓縮比例 JPGEncoder(60),這樣存的檔案體積會比較小,比較不容易掛
*/
import mdm.*;
import com.adobe.images.PNGEncoder;
import com.adobe.images.JPGEncoder;
//Declare global variables
var fileFolderPath:String; // 資料夾的位置
var fileName:String; // 文字檔(log)檔名
var uniqueName:String;
// 用 Flash CS3 的話一定要先用這個指令來 Initiate
mdm.Application.init(this,OnInit);
// 可接收關掉程式時的 Event
mdm.Application.enableExitHandler();
function OnInit():void {
OpenFile();
}
function OpenFile() {
var myDate:Date = new Date();
var folderExists:Boolean;
uniqueName = myDate.toDateString() + " - "
+ myDate.hours
+"_" + myDate.minutes
+"_" + myDate.seconds ;
fileFolderPath = mdm.System.Paths.desktop + "Record-" + uniqueName + "\\";
folderExists = mdm.FileSystem.folderExists(fileFolderPath);
if( folderExists == true ){
; // 資料夾已經存在
}
else{
// 資料夾不存在就create一個
mdm.FileSystem.makeFolderUnicode(fileFolderPath);
}
// log 檔名
fileName = "Log.txt";
// 在第一行寫入試著在第一行寫入 "#Log\n"
mdm.FileSystem.saveFileUnicode(fileFolderPath + fileName, "#Log\n");
}
// 要寫 log 的時候就把 string pass 給 WriteLog(your_string)
function WriteLog(msg:String) {
appendFile(msg);
}
function appendFile(eMsg:String) {
mdm.FileSystem.appendFileUnicode(fileFolderPath + fileName, eMsg);
}
// 回傳畫著這個 MovieClip 的 BitmapData
function mc2Bitmap(mc1:MovieClip):BitmapData {
var myBitmap:BitmapData = new BitmapData(mc1.width, mc1.height, true, 0);
myBitmap.draw(mc1);
return myBitmap;
}
// 將 MovieClip 轉成 名為 fileName.png 的 PNG 圖檔
function MovieClipToPNG( target_mc:MovieClip, fileName:String):void {
BitmapDataToPNG( mc2Bitmap(target_mc) , fileName );
}
// 將 MovieClip 轉成 名為 fileName.jpg 的 JPG 圖檔
function MovieClipToJPG( target_mc:MovieClip, fileName:String):void {
BitmapDataToJPG( mc2Bitmap(target_mc) , fileName );
}
// 將 BitmapData 轉成 名為 fileName.png 的 PNG 圖檔
function BitmapDataToPNG( targetB:BitmapData, fileName:String ):void {
var baString:String;
var bpd:BitmapData = targetB;
var ba:ByteArray;
var resultString:String;
ba = PNGEncoder.encode(bpd);
var g:Number;
g = 0;
resultString = ba[0];
// MDM 的存檔格式(由 | 分隔)
for (g = 1; g < ba.length; g++) {
resultString += "|" + ba[g];
}
mdm.FileSystem.BinaryFile.setData (resultString);
mdm.FileSystem.BinaryFile.writeData( root["fileFolderPath"] + fileName + ".png" );
}
// 將 BitmapData 轉成 名為 fileName.jpg 的 JPG 圖檔
function BitmapDataToJPG( targetB:BitmapData, fileName:String ):void {
var baString:String;
var bpd:BitmapData = targetB;
var ba:ByteArray;
var resultString:String;
var jpgEncorder:JPGEncoder = new JPGEncoder(60);
ba = jpgEncorder.encode (bpd);
var g:Number;
g = 0;
resultString = ba[0];
// MDM 的存檔格式(由 | 分隔)
for (g = 1; g < ba.length; g++) {
resultString += "|" + ba[g];
}
mdm.FileSystem.BinaryFile.setData(resultString);
mdm.FileSystem.BinaryFile.writeData( root["fileFolderPath"] + fileName + ".jpg" );
}
Thursday, December 6, 2007
SWF, EXE, MDM 的 exe 都能關掉程式的 function
mdm.Application.init(this,OnInit);
mdm.Application.enableExitHandler();
function OnInit():void {
//mdm.Dialogs.prompt("Zinc with Flash CS3, Text Saver!");
}
// 想關程式的時候就 call MyClose()
function MyClose(){
fscommand( "quit" ); // for flash player
mdm.Application.exitWithCode(0); // for mdm
}
/*
這樣子不管單純用 swf, or swf -> exe 都可以透過 fscommand 來關程式 (用 Flash IDE開發, Debug Mode的時候)
而在用 mdm 包裝後, mdm.Application.exitWithCode(0) 就可以關程式了
所以不管你是在什麼階段都能用。
*/
Monday, December 3, 2007
Note : Adobe Flex 2 (Training from the Source)
Lesson 24 Using Shared Objects
Note: Essential ActionScript 3.0
Chap 13 Exceptions and Error Handling
講的是 try/ catch/finally 的使用跟邏輯。有學過Java 的人應該很熟練。
Chap 14 Garbage Collection
- 拿掉 Event Handler
- 停止 timer 跟 intervals
- 停止 playhead (不繼續播放)
- 把唯一由自己reference 到的object 也 deactivate。
另外一點就是,如果可以重複使用一個Object就重複使用,而
使用 MDM 包裝 swf 檔成為全螢幕執行的設定方式
Size/Position-> Window Size: MovieSize
Extras : Maximized
from Jones
Friday, November 30, 2007
想把 MovieClip (-> Sprite -->DisplayObject) 恢復原來的大小
把 scaleX, scaleY ,設回 1 的時候就會恢復原來的大小
this.scaleY = 1.0;
Thursday, November 29, 2007
放大 Bitmap 的時候(或是內含Bitmap 的 DisplayObject) 可提昇Display 品質的參數
// 設定了 smoothing, pixelSnapping 後就好很多
var tempBitmapData:BitmapData;
var tempBitmap:Bitmap;
var temp_mc:MovieClip;
temp_mc = new MovieClip();
function mc2Bitmap(mc1:MovieClip):BitmapData {
myBitmap.draw(mc1);
return myBitmap;
}
tempBitmapData = mc2Bitmap( new WhiteBackBoy1());
// WhiteBackBoy1 : 有內容的 MovieClip (自這裡是把他的內容"印"成 BitmapData )
tempBitmap = new Bitmap( tempBitmapData );
tempBitmap.pixelSnapping = PixelSnapping.AUTO;
tempBitmap.smoothing = true;
temp_mc.addChild( tempBitmap );
addChild( temp_mc );
stage.addEventListener( KeyboardEvent.KEY_DOWN , KeyDownEventHandler);
function KeyDownEventHandler(event:KeyboardEvent) {
if (event.keyCode == Keyboard.UP) {
trace("Keyboard.UP");
temp_mc.scaleX *= 1.1;
temp_mc.scaleY *= 1.1;
} else if (event.keyCode == Keyboard.DOWN) {
trace("Keyboard.DOWN");
temp_mc.scaleX /= 1.1;
temp_mc.scaleY /= 1.1;
}
}
Wednesday, November 28, 2007
SharedObject 的 data 可以傳給其他 function 當作 reference 來改 data 下面的屬性的值
var bytes:ByteArray = new ByteArray();
var example:SharedObject = SharedObject.getLocal( "example8");
var tempList:Array;
var targetObject:Object;
function Target( o:Object ) {
targetObject = o;
targetObject.times = 10;
}
function AddTarget() {
targetObject.times++;
}
if ( example.data.times == undefined ) {
example.data.times = new Number();
var i:Number;
i = 0;
example.data.times = i;
trace("i:" + i); // first time, 0
trace("Before Target():" + example.data.times);// first time, 0
Target( example.data );
trace("After Target():" + example.data.times);// first time, 10
AddTarget();
AddTarget();
AddTarget();
AddTarget();
AddTarget();
trace("After 5 AddTarget():" + example.data.times);// first time, 15
example.flush();
}
else{
trace("example.data.times last time:" + example.data.times); // from the second time, 15
}