2009/11/16

複製物件

//--------------------------------------------
var mcA:McA=new McA();
addChild(mcA);
mcA.addChild(new McB);
mcA.x=50;
mcA.y=50;

var cc:Class=Object( mcA ).constructor;

var dmcA:McA=new cc();

addChild(dmcA);
dmcA.x=300;
dmcA.Y=300;

2009/11/10

php array sort by key

$datalist=$db->get_results($sql);

$c=0;
foreach($datalist  as $key => $d)
{

$a_map[$key]['vote'] = $d['vote'];

}

$r=arsort($a_map);
print_r($a_map);

2009/10/30

convert -resize 150x150^ -gravity center -extent 150x150 ".$from_file." ".$to_file

2009/10/20

build application by facebook ,step 1

ADOBE針對facebook上開發網路應用程式的說明
http://www.adobe.com/devnet/facebook/

大致分為6種

iFrame Facebook application
不多說,就是iframe

FBML Facebook application
用facebook的訊息來散播

2009/10/8

BulkLoader + ZedBox

BulkLoader是一個非常好用的讀取器
支援xml、img、swf、txt等多種檔案的讀取

最重要的是,他可以減少同時間過多Loader讀取所發生的錯誤
像是讀取相簿的縮圖之類,


使用方式很簡單
loader.add(img);
loader.get(img).addEventListener(Event.COMPLETE,onImgLoadComplete);
loader.start();

//最後取得e.currentTarget as LoadingItem
//就可以獲得所讀取的內容了
bulk-loader
http://code.google.com/p/bulk-loader/



package 
{
 import br.com.stimuli.loading.loadingtypes.LoadingItem;
 import flash.display.Bitmap;
 import flash.display.Graphics;
 import flash.display.MovieClip;
 import flash.display.Sprite;
 import flash.events.Event;
 import flash.events.MouseEvent;
 import flash.filters.BlurFilter;
 import idv.cjcat.zedbox.*;
 import idv.cjcat.zedbox.filters.AlphaZFilter;
 import idv.cjcat.zedbox.filters.BlurZFilter;
 import idv.cjcat.zedbox.geom.Vec3;
 import br.com.stimuli.loading.*;
 
 public class Main extends Sprite
 {
  private var scene:ZedScene = new ZedScene;
  private var rootZsp:ZedSprite;
  
  private var loader :BulkLoader = new BulkLoader("main-site");
  
  public function Main():void
  {
   if (stage) init();
   else addEventListener(Event.ADDED_TO_STAGE, init);
  }
  private var zspNum:int = 0;
  private function init(e:Event = null):void 
  {
   //trace("init");
   removeEventListener(Event.ADDED_TO_STAGE, init);
   // entry point
   
   addChild(scene);
   scene.x = stage.stageWidth * 0.5;
   scene.y = stage.stageHeight * 0.5;
   
   rootZsp= new ZedSprite();
   scene.addChild(rootZsp);
   rootZsp.z = 3000;
   
   for (var i:int = 0; i <= 30; i++)
   {
    var img:String = "img/" + i + ".jpg";
    //trace(img);
    loader.add(img);
    loader.get(img).addEventListener(Event.COMPLETE,onImgLoadComplete)
   
    
   }
   loader.start();
   addEventListener(Event.ENTER_FRAME, onEnterFrame);
   stage.addEventListener(MouseEvent.MOUSE_WHEEL, onMouseWheel);
   

   var afilter:AlphaZFilter = new AlphaZFilter();
   afilter.nearPlane = 1000;
   afilter.farPlane = 7000;   
   afilter.farRange = afilter.nearRange = 2000;
   
   scene.zFilters.push(afilter);
   
   var bfilter:BlurZFilter = new BlurZFilter();
   bfilter.nearPlane = 1000;
   bfilter.farPlane = 7000;   
   bfilter.farRange = bfilter.nearRange = 1000;
   
   scene.zFilters.push(bfilter);
  
  }
  
 
  public function onImgLoadComplete(e:Event):void
  {
   //trace(e.currentTarget);
   var zsp:ZedSprite = new ZedSprite();
   
   
   var item:LoadingItem = e.currentTarget as LoadingItem;
   if (item.isImage())
   {
    var bmp:Bitmap = item.content as Bitmap;
    
    zsp.addChild(bmp);
    bmp.x = bmp.width * -0.5;
    bmp.y = bmp.height * -0.5;
    
    zsp.addEventListener(MouseEvent.MOUSE_OVER, onMouseOver);
    zsp.addEventListener(MouseEvent.MOUSE_OUT, onMouseOut);
   }
   
   
   
   
   rootZsp.addChild(zsp);
   zsp.z = 300 * zspNum - 3000;
   zsp.x = Math.random() * 2000 - 1000;
   zsp.y = Math.random() * 1000 - 1000;
   //zsp.x = 200;
   //zsp.y = 200;
   //zsp.z = 200 * i;
   //trace(i);
   zspNum++;
    
  }
  public function onMouseOver(e:MouseEvent):void
  {
   
   var zsp:ZedSprite = e.currentTarget as ZedSprite;
   
   if (zsp.alpha > 0.7)
   {
    trace("onMouseOver");
    zsp.getChildAt(0).scaleX = zsp.getChildAt(0).scaleY = 3;
    
    zsp.getChildAt(0).x = zsp.getChildAt(0).width * -0.5;
    zsp.getChildAt(0).y = zsp.getChildAt(0).height * -0.5;
   }
  }
  
  public function onMouseOut(e:MouseEvent):void
  {
   var zsp:ZedSprite = e.currentTarget as ZedSprite;
   zsp.getChildAt(0).scaleX = zsp.getChildAt(0).scaleY = 1;
   
   zsp.getChildAt(0).x = zsp.getChildAt(0).width * -0.5;
   zsp.getChildAt(0).y = zsp.getChildAt(0).height * -0.5;
  }
  public function buildZsp():ZedSprite
  {
   var sp:Sprite = new Sprite();
   
   sp.graphics.beginFill(int(Math.random()*255)*255);
   sp.graphics.drawCircle(0, 0,50);
   sp.graphics.endFill();
   
   var zsp:ZedSprite = new ZedSprite();
   zsp.addChild(sp);
   return zsp;
  }
  public function onEnterFrame(e:Event):void
  { 
   scene.render(); 
   
   //scene.camera.position.x = mouseX-stage.stageWidth*0.5;
   //scene.camera.position.y = mouseY-stage.stageHeight*0.5;
   //trace(scene.camera.rotation);
   scene.camera.direction.x += (mouseX - stage.stageWidth * 0.5) * 0.0002;
   scene.camera.direction.y += (mouseY - stage.stageHeight * 0.5) * 0.0002;
   
   rootZsp.rotationY++;
  }
  public function onMouseWheel(e:MouseEvent):void
  {
   //scene.camera.focalLength+=e.delta*0.1;
   //scene.camera.position.z += e.delta * 50;
   //scene.camera.focalLength+= e.delta * 50;
   //scene.camera.zoom+= e.delta
  }
 }
}

Build your first Facebook application 筆記(1)

1、登入facebook的開發者網頁http://developer.facebook.com/

 

教學影片

VI 指令圖


這東西真方便,設成半透明
拿來當桌面好了

2009/10/7

google Wave 8分鐘 簡介



http://medialand.com.tw/blog/article.asp?id=1095

總算懂他的功能了
會打扒很多視訊會議軟體吧

2009/10/4

regexp

/<cut file=\"[^\"]+\">(.*?)<\/cut>/

取出紅色部分
內容

2009/10/1

zedBox 試作

zedBox是由cj大所開發的as3 libery
由flash 9跟 flash 10

基本上用法跟一般3d 定位方式差不多
提供了兩個特效
AlphaZFilter與BlurZFilter

濾鏡的用法如下,以下是小弟推測的心得
var afilter:AlphaZFilter = new AlphaZFilter();
afilter.nearPlane = 500; //最近平面
afilter.farPlane = 2500;  //最遠平面,在nearPlane~farPlane面的物件將會清楚呈現

afilter.farRange = afilter.nearRange = 1000;
//nearPlane與farPlane外的範圍
//簡單說farPlane(2500)~farPlane+farRange (共3500)範圍內的物件將會逐步的提昇濾鏡效果
       
scene.zFilters.push(afilter);//套用濾鏡

zedBox google code >> http://code.google.com/p/zedbox/
cj blog>>  http://cjcat.blogspot.com/

package 
{
 import flash.display.Graphics;
 import flash.display.MovieClip;
 import flash.display.Sprite;
 import flash.events.Event;
 import flash.events.MouseEvent;
 import flash.filters.BlurFilter;
 import idv.cjcat.zedbox.*;
 import idv.cjcat.zedbox.filters.AlphaZFilter;
 import idv.cjcat.zedbox.filters.BlurZFilter;
 import idv.cjcat.zedbox.geom.Vec3;
 
 public class Main extends Sprite
 {
  private var scene:ZedScene = new ZedScene;
  public function Main():void
  {
   if (stage) init();
   else addEventListener(Event.ADDED_TO_STAGE, init);
  }
  
  private function init(e:Event = null):void 
  {
   removeEventListener(Event.ADDED_TO_STAGE, init);
   // entry point
   
   addChild(scene);
   scene.x = stage.stageWidth * 0.5;
   scene.y = stage.stageHeight * 0.5;
   
   
   for (var i:int = 0; i <= 30; i++)
   {
    var zsp:ZedSprite = buildZsp();
    scene.addChild(zsp);
    zsp.z = 200 * i;
    zsp.x = Math.random() * 1000 - 500;
    zsp.y = Math.random() * 1000 - 500;
    //zsp.x = 200;
    //zsp.y = 200;
    //zsp.z = 200 * i;
    //trace(i);
   }
   
   addEventListener(Event.ENTER_FRAME, onEnterFrame);
   stage.addEventListener(MouseEvent.MOUSE_WHEEL, onMouseWheel);
   

   var afilter:AlphaZFilter = new AlphaZFilter();
   afilter.nearPlane = 500;
   afilter.farPlane = 2500;   
   afilter.farRange = afilter.nearRange = 1000;
   
   scene.zFilters.push(afilter);
   
   var bfilter:BlurZFilter = new BlurZFilter();
   bfilter.nearPlane = 500;
   bfilter.farPlane = 2500;   
   bfilter.farRange = bfilter.nearRange = 500;
   
   scene.zFilters.push(bfilter);
  
  }
  public function buildZsp():ZedSprite
  {
   var sp:Sprite = new Sprite();
   
   sp.graphics.beginFill(int(Math.random()*255)*255);
   sp.graphics.drawCircle(0, 0,50);
   sp.graphics.endFill();
   
   var zsp:ZedSprite = new ZedSprite();
   zsp.addChild(sp);
   return zsp;
  }
  public function onEnterFrame(e:Event):void
  { 
   scene.render(); 
   scene.camera.position.x = mouseX-stage.stageWidth*0.5;
   scene.camera.position.y = mouseY-stage.stageHeight*0.5;
  }
  public function onMouseWheel(e:MouseEvent):void
  {
   scene.camera.position.z += e.delta * 50;
   //scene.camera.focalLength+= e.delta * 50;
   //scene.camera.zoom+= e.delta
  }
 }
}

2009/9/22

php 常用的特殊符號

http://hi.baidu.com/xinghuali/blog/item/7a735782a9b4a9a50cf4d236.html

其中比較特殊的簽號

其他運算符號
        $         變數符號             
        &        變數的指標(加在變數前)
        @       不顯示錯誤信息(加在函數前)
        ->        物件的方法或者屬性
        =>       陣列的元素值
        ? :       三元運算子  

flash & p2p

flash 10支援p2p了(驚)!!

之前用ElectroServer開發多人連線遊戲
總覺得這所有的訊號都要經過server才能傳遞給對方

推想如果要建多人視訊,主機的loading不就大到爆

不小心看到這則新聞
http://waterxbread.blogspot.com/2009/08/flash-p2p.html

flash 10 支援p2p了!!

p2p的好處就是可以比較不重要的訊息透過這種方式傳遞
像是不需要存取到資料庫的訊息
如多人遊戲中的對談
例如多人遊戲中的兩個人在pk,撇開作弊因素,過程的打法不需要讓伺服器知道,最後的結果告訴伺服器就好

可以推測,之後facebook上的小遊戲會有新一波改變

2009/9/20

vim常用語法

搜尋取代
1代表第一行,$是最後一行,搜尋news字串,取代成topic字串,s代表搜尋取代
:1,$s/news/topic/g

搜尋取代,搜尋全部的行可直接用%
:%s/news/topic/g

搜尋else字串,公用else取代topicnews
用正規表示式將news框起來,並代到取得字串的\1
多種字串框時,則用\1、\2、\3……
:%s/^\(news\)/topic\1/g


將每一行前面加上#號
:1,$s/^/#/g


全文自動排版
gg=G


yy 剪下行
y2 剪下本行至下兩行
p 貼上行

一些簡單的screen語法

一些簡單的screen語法

screen -U -S sname 以utf-8的編碼,並以sname為標籤建立screen ,並

-U 以utf8編碼
-r 回覆上次登入
-d 強制回覆
-ls 列出所有的screen


進入screen狀態後的操作

Ctrl+a c 開啟新的視窗,並同時切換到這個新的視窗

Ctrl+a n 或 C-a (space) 切換到下一個視窗

Ctrl+a p 切換到上一個視窗

Ctrl+a 0 切換到第 0 個視窗

Ctrl+a (1..9) 切換到第 (1..9) 個視窗

var_dump & print_r

以前寫php常用
print_r把整個陣列的內容印出來

學弟跟我說了另一個 var_dump
可以把整個陣列印出來
另外還補上陣列內容的形態

參考網址
http://tw.php.net/var_dump

2009/9/5

移除removexss攻擊語法

xss攻擊

何謂xss攻擊
可參考http://anti-hacker.blogspot.com/2008/01/xsscross-site-script.html
簡單的說
就是在post欄位中塞一些惡意語法

以下是移除xss語法的function
參考http://kallahar.com/smallprojects/php_xss_filter_function.php

function RemoveXSS($val) {
// remove all non-printable characters. CR(0a) and LF(0b) and TAB(9) are allowed
// this prevents some character re-spacing such as
// note that you have to handle splits with \n, \r, and \t later since they *are* allowed in some inputs
$val = preg_replace('/([\x00-\x08,\x0b-\x0c,\x0e-\x19])/', '', $val);

// straight replacements, the user should never need these since they're normal characters
// this prevents like
$search = 'abcdefghijklmnopqrstuvwxyz';
$search .= 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
$search .= '1234567890!@#$%^&*()';
$search .= '~`";:?+/={}[]-_|\'\\';
for ($i = 0; $i < val =" preg_replace('/(&#[xX]0{0,8}'.dechex(ord($search[$i])).';?)/i'," val =" preg_replace('/(�{0,8}'.ord($search[$i]).';?)/'," ra1 =" Array('javascript'," ra2 =" Array('onabort'," ra =" array_merge($ra1," found =" true;" found ="=" val_before =" $val;" i =" 0;" pattern =" '/';" j =" 0;"> 0) {
$pattern .= '(';
$pattern .= '(&#[xX]0{0,8}([9ab]);)';
$pattern .= '|';
$pattern .= '|(�{0,8}([9|10|13]);)';
$pattern .= ')*';
}
$pattern .= $ra[$i][$j];
}
$pattern .= '/i';
$replacement = substr($ra[$i], 0, 2).''.substr($ra[$i], 2); // add in <> to nerf the tag
$val = preg_replace($pattern, $replacement, $val); // filter out the hex tags
if ($val_before == $val) {
// no replacements were made, so exit the loop
$found = false;
}
}
}
return $val;
}