Flash 執行PHP

語法跟Flash 外部載入文字檔 大同小異,但多加了要傳參數

AS2.0

var loader:LoadVars=new LoadVars();
loader.load("http://localhost/xxx.php?acc=a&pwd=b");
loader.onData=function(re:String){
trace(re);
}

AS3.0

var myURLReq:URLRequest = new URLRequest();
myURLReq.url="http://localhost/xxx.php?acc=a&pwd=b";
var myURLLoader:URLLoader = new URLLoader();
myURLLoader.load(myURLReq);
myURLLoader.addEventListener(Event.COMPLETE, function(e:Event){
trace(myURLLoader.data);
});


php

$account= $_GET['acc'];
$password= $_GET['pwd'];
echo "a1=".$account;
echo "p1=".$password;

範例檔:
AS2.0 http://www.box.net/shared/5suo5kcva8
AS3.0 http://www.box.net/shared/qn4ityqo1n
PHP http://www.box.net/shared/i3vyy6urs7

AppServ架站

每次都會忘了步驟,有人放教學,記下來
http://linux0911.no-ip.info/my_style/doc/appserv2/

Flash 動態Class名稱 使用getDefinitionByName方法(AS3.0)

昨天碰到一個問題,有時我們會在元件庫上,為元件"綁定類別"(Linkage),程式中要用時再new出這個元件。
ex:

var mc:MovieClip=new mc1();
stage.addChild(mc);


假設我有mc1~mc3,3個MovieClip,要隨機產生一個,所以我的程式碼如下:

var ranNum:int=Math.floor(Math.random()*3)+1;//得到1~3間的亂數
var mc:MovieClip;
switch(ranNum){
case 1:
mc=new mc1();
break;
case 2:
mc=new mc2();
break;
default :
mc=new mc3();
}
stage.addChild(mc);


那…如果我有10個呢? case寫10個判斷? 100個呢?ctrl+c、ctrl+v按個沒完沒了?
所以~找到了一個getDefinitionByName()的函數。
修改的程式碼如下:

var ranNum:int=Math.floor(Math.random()*3)+1;//得到1~3間的亂數
var tempClass=getDefinitionByName("mc"+ranNum);
var mc:MovieClip=new tempClass();
stage.addChild(mc);

簡潔多了吧~

範例:
http://www.box.net/shared/vrj4y61y9i

Flash 外部載入文字檔

文字檔的檔名為test.txt,與fla檔放在同一個資料夾

AS2.0
var myLoader = new LoadVars();
myLoader.load("test.txt");

myLoader.onData = function(str:String) {
trace(str);
};

AS3.0
var myURLReq:URLRequest = new URLRequest();
myURLReq.url = "test.txt";
var myLoader:URLLoader = new URLLoader();
myLoader.addEventListener("complete", onC);

myLoader.load(myURLReq);

function onC(e) {
trace(myLoader.data);
}

Flash 播放時鎖選單及右鍵

fscommand("showmenu", false);//封鎖右鍵選單及上面的menu選單
fscommand("trapallkeys",true);//封鎖"CTRL+ENTER"鍵

http://tw.knowledge.yahoo.com/question/question?qid=1509070708413

下載進度

AS2.0
範例檔:

AS3.0
範例檔:http://www.box.net/shared/1g7byr7u4j

http://tw.knowledge.yahoo.com/question/question?qid=1009062804614

Flash連結

AS2.0
getURL("http://www.google.com.tw","_blank");

AS3.0
import flash.net.*;
var myurl:URLRequest=new URLRequest("http://www.google.com.tw");
navigateToURL(myurl,"_blank");

http://tw.knowledge.yahoo.com/question/question?qid=1009050606129