2010-11-10 03:18

[C/C++語言] 解析命令列的參數

// xxxx.exe -cfg path -tg target

#include <stdio.h>
#include <string.h>

int main(int argc, char *argv[]) {
    int status = 0;

    for (int i=1; i<argc; i++){
        if (!strcmp(argv[i], "-tg")){
            i++;
            if (i < argc){
                printf("target is %s\n",argv[i]);
            }else {
                status=1; break;
            }
        }else if (!strcmp(argv[i], "-cfg")){
            i++;
            if (i < argc){
                printf("config path is %s\n",argv[i]);
            }else {
                status=1; break;
            }
        }
    }
    return status;
}

看到前輩寫的 code,記錄一下,原來很簡單就可以做到。
2010-11-03 06:30

[PHP] SOAP - Webservice Helper

Webservice Helper 這個套件真是一個方便的好工具
它必須 Base 在 PHP SOAP 原生套件的上面
能夠透過 PHP 裡的註解自動產生 WSDL File

詳細的用法在他的範例中都介紹得很清楚
2010-11-03 06:19

[JavaScript] replace 另類用法

function replacer(str, p1, p2, offset, s){
  return str + " - " + p1 + " , " + p2;
}
var newString = "XXzzzz".replace(/(X*)(z*)/, replacer);
//newString to "XXzzzz - XX , zzzz"


var re = /(\w+)\s(\w+)/;
var str = "John Smith";
var newstr = str.replace(re, "$2, $1");
print(newstr);
//This prints "Smith, John".

Possible nameSupplied value
strThe matched substring. (Corresponds to $& above.)
p1, p2, ...The nth parenthesized submatch string, provided the first argument to replace was a RegExp object. (Correspond to $1, $2, etc. above.)
offsetThe offset of the matched substring within the total string being examined. (For example, if the total string was "abcd", and the matched substring was "bc", then this argument will be 1.)
sThe total string being examined.

引用自: replace - MDC
2010-11-01 05:10

[ActionScript] loadMovieClip

原生的 loadMovie 少了 onComplete 的追蹤,而 MovieClipLoader 使用起來又太囉唆,索性就對 MovieClip 的 prototype 上加了 loadMovieClip function,至少會撰寫時快樂一點。
MovieClip.prototype.loadMovieClip = function(src:String, onComplete:Function) :MovieClip {
    var mcLoader:MovieClipLoader = new MovieClipLoader();
    mcLoader.addListener({onLoadInit:onComplete});
    mcLoader.loadClip(src,this);
    return this;
};


使用方式:
var container:MovieClip = createEmptyMovieClip("container", this.getNextHighestDepth());

container._x = container._y = 0;
container.visible = false;

container.loadMovieClip("vodBlock.swf", function(container:MovieClip) {
    trace("load complete");
    container._visible = false;
});

參考來源:
Flash CS4 Professional ActionScript 2.0: loadClip (MovieClipLoader.loadClip 方法)
2010-11-01 05:00

[ActionScript] 幾種物件撰寫方式

一般撰寫的方式:雖然沒有建構物件,但別忘了場景本身就是一個物件,所以下面的撰寫方式已經再使用物件了。
var dataStr="jax";
var loadMc:MovieClip = createEmptyMovieClip("container", this.getNextHighestDepth());
loadMc._x = loadMc._y = 0;
loadMc.visible = false;

var mcLoader:MovieClipLoader = new MovieClipLoader();
mcLoader.addListener(this);
mcLoader.loadClip("vodBlock.swf",loadMc);

function onLoadInit(loadMc:MovieClip) {
    loadMc._visible = false;
    loadMc.text=this.dataStr;
}    


使用 JSON 的撰寫方式:如果只是單純的建立一個物件,下面這個寫法應該是最簡潔的,但這並不是一個很好 ActionScript 風格。
var myObject = {
    dataStr:"jax",
    loadMc:null,
    init:function(){
        this.loadMc= createEmptyMovieClip("container", this.getNextHighestDepth());
        this.loadMc._x = this.loadMc._y = 0;
        this.loadMc.visible = false;

        var mcLoader:MovieClipLoader = new MovieClipLoader();
        mcLoader.addListener(this);
        mcLoader.loadClip("vodBlock.swf",this.loadMc);
    },
    onLoadInit:function(loadMc:MovieClip) {
        loadMc._visible = false;
        loadMc.text=this.dataStr;
    }
}    
    
myObject.init();    


利用 Class 撰寫方式:這是 ActionScript 標準風格的撰寫方式,也比較正規一點。
class MyClass{
    var dataStr:String;
    var loadMc:MovieClip;
    
    function MyClass(){
        this.dataStr="jax"
        this.loadMc= createEmptyMovieClip("container", this.getNextHighestDepth());
        this.loadMc._x = container._y = 0;
        this.loadMc.visible = false;

        var mcLoader:MovieClipLoader = new MovieClipLoader();
        mcLoader.addListener(this);
        mcLoader.loadClip("vodBlock.swf",this.loadMc);        
    }
    
    function onLoadInit(loadMc:MovieClip) {
        loadMc._visible = false;
        loadMc.text=this.dataStr;
    }
}    
new MyClass();    


延伸原生 Class 的撰寫方式:如果規劃的好這會是一個很省事的撰寫方式。
class MyMovieClip extends MovieClip{
    var dataStr:String;
 
    function MyMovieClip(){
        this.dataStr="jax"
        this._x = this._y = 0;
        this.visible = false;
    }

    function loadMovieClip(src:String) :MovieClip {
        var mcLoader:MovieClipLoader = new MovieClipLoader();
        mcLoader.addListener(this);
        mcLoader.loadClip(src,this);        
        return this;
    }
    
    function onLoadInit(mc:MovieClip) {
        this = MyMovieClip(loadMc);
        this._visible = false;
        this.text=this.dataStr;
    }
}    

var loadMc:MyMovieClip = MyMovieClip( createEmptyMovieClip("container", this.getNextHighestDepth()) );
loadMc.loadMovieClip("vodBlock.swf");


物件的撰寫有幾個要點:
  1. 搞清楚 this 到底是誰?這大概也是入門時最容易被弄到翻過來的問題之一
  2. 物件的規劃,別寫了半天的『物件導向』跟寫『結構語言』沒什麼分別。
2010-11-01 02:54

[ActionScript] Function bind

由於 ActionScript 2.0 無法對 Function 做延伸,所以只好用一般函數的方式處理了。
function bind(func:Function, target:Object):Function{
    return function(){
        arguments.unshift(this);
        func.apply(target, arguments);
    };
};

參考來源:
Function.prototype.bind
FLASH - Can I extend Function's prototype in ActionScript?
2010-11-01 02:47

[JavaScript] Function.prototype.bind

Function.prototype.bind = function(target){
    var func=this;
    return function(){
        arguments.unshift(this);
        func.apply(target, arguments);
    };
};

參考來源:
Function.prototype.bind
FLASH - Can I extend Function's prototype in ActionScript?