2010年3月9日 星期二

在Flash中使用AS3.0將圖片水平反轉

package flashAs {
import flash.display.BitmapData;
import flash.geom.Matrix;
//具有圖片反轉功能的類別
public class ImageRotation extends Sprite{
private var matrix:Matrix;
private var sourceBD:BitmapData;

//建構子, 設定圖片來源和座標
public function ImageRotation (BD:BitmapData, X:int, Y:int){
sourceBD= BD;
this.x = X; this.y = Y;
//--設定變型矩陣的物件
matrix = new Matrix();
matrix.a=-1;
matrix.b = Math.sin( (180/180) * Math.PI);
matrix.tx= sourceBD.width;
this. goRecovery();
}
//進行水平反轉
public function goRotation (){
this.graphics.clear();
this.graphics.beginBitmapFill(sourceBD, matrix, false);
this.graphics.drawRect(0, 0, sourceBD.width, sourceBD.height);
this.graphics.endFill();
}
//恢復原始圖片
public function goRecovery(){
this.graphics.clear();
this.graphics.beginBitmapFill(sourceBD);
this.graphics.drawRect(0, 0, sourceBD.width, sourceBD.height);
}
}
}

2010年2月11日 星期四

flash使用AS3.0水平反轉圖片

使用Matrix來實現, 假設sourceBD是原始圖片, 則newBD為反轉後的圖片

----------------------------------------------
import flash.geom.Matrix;
import flash.display.BitmapData;

var sourceBD:BitmapData = new BitmapData():

var matrix:Matrix = new Matrix(-1, Math.sin( (180/180) * Math.PI), 0, 0, 0, 0);
matrix.a = -1; //把x反向縮放1倍
matrix.b = Math.tan( (180/180) * Math.PI); //表示y軸傾斜180度
matrix.tx= sourceBD.width;
newBD= new BitmapData(BD.width, BD.height);
newBD.draw(BD,matrix);

2009年10月27日 星期二

判斷使用者是否正選取本頁面

在製作聊天室的網頁時,需要使用到這個功能!

例如有人對你說話時,而你並不在聊天室的那個頁面視窗時!

可以經由這個判斷來提醒使用者,如果沒有在聊天室頁面,

就將網頁的TITLE顯示如"XXX對你說"類似的資訊!

這樣就能達到不在聊天室也能知道是不是有人對你說話了!

下面是判斷的程式碼:

<script type="text/javascript" src="../Scripts/prototype.js"></script>

var _FOCUSED = true;
//適用IE
if(navigator.userAgent.indexOf("MSIE") > 0){
Event.observe(document, 'focusout', function(){
_FOCUSED = false;
}, false);
Event.observe(document, 'focusin', function(){
_FOCUSED = true;
}, false);
}
else{
//適用FF
window.onblur = function(){
_FOCUSED = false;
}
window.onfocus = function(){
_FOCUSED = true;
}
}


2009年10月14日 星期三

解決IE6的PNG透明圖

在IE6中並不支援PNG的透明圖片,但可依照下面方法達到透明圖。

一開始需載入jquery.js與jquery.ifixpng.js的套件,

還有一個重點就是需要將此套件使用到的圖片 pixel.gif 儲存到 images/pixel.gif 中,

若想要更改圖片擺放位置,可以到query.ifixpng.js檔案中搜尋"images/pixel.gif"並修改即可,


下面是將全部的物件都使用透明化的概略程式碼
==============================================
<script type="text/javascript"> 
<!--  
$(function(){
     $("*").ifixpng(); 
}); 
//--> 
</script>
==============================================

若只針對PNG來做透明化可用:$('img[@src$=.png]').ifixpng();

2009年7月22日 星期三

Smarty樣板常用語法

宣告變數
{assign var=v value=1default:0}

foreach用法
{foreach from=$items item=value}
show:{$value}
{foreachelse}
is empty.
{/foreach}
詳細用法請參考:http://www.smarty.net/manual/en/language.function.foreach.php


if用法
{if $var=="aa"}
var:aa
{elseif $var=="bb}
var:bb
{else}
var:cc
{/if}

section用法
{section name="forLoop" start=1 loop=10}
forLoop is 1 to 10
{/section}



參考網址:http://www.jaceju.net/blog/?cat=8

2009年7月21日 星期二

JavaScript常用內建函數

  • confirm(String)
    跳出詢問視窗,有是和否的選項可選擇,選是則傳回True,否為False。
  • alert(String)
    跳出訊息視窗。

JavaScript的內建字串函數

  • indexOf(findString, [startingIndex])
    傳回某字串在字串物件內的位置。 findString 是要找尋的字串; startingIndex 是選擇性參數, 表示要由字串物件開頭的第幾個字元開始找尋, 如果沒有指定, 就由開頭第一個字元開始找。 如果找不到該字串, 就傳回 -1。 註:字串的第一個字元的位置是 0。
  • lastIndexOf(findString, [startingIndex])
    與 indexOf 相似, 不同之處在於 lastIndexOf 是由字串結尾開始找, startingIndex 也是由字串結尾數起。
  • toUpperCase() 和 toLowerCase()
    將 text 字串變數內的所有字元轉成大階或小階
  • charAt(index)
    傳回字串物件內某個位置的字元。 index 是字串物件內的位置, 數值可以由 0 至text.length - 1
  • substring(firstIndex, lastIndex)
    傳回字串物件某個部份的字串。 firstIndex 和 lastIndex 分別是該部份字串在字串物件內的開頭和結尾位置。
  • escape(string)
    傳回 string 的 16 進制編碼得出來的字串
  • eval(string)
    把 string 當作 JavaScript 的敘述來執行
  • isNaN(test_value)
    檢查 test_value 是否"非數目"型態 (is Not a Number)
  • parseFloat(string)
    傳回 string 轉成浮點小數後的數目
  • parseInt(string, base)
    傳回 string 轉成 10 進制後的整數; base 是 string 的數制, 它是選擇性的參數, 如果不指定就把 string 當作 10 進制。
  • unescape(string)
    傳回以 16 進制編碼字串的原本字串, 功能與 escape() 剛好相反
  • length
    取得字串的長度
  • charCodeAt
    傳回字元的 ASCII 值
  • fromCharCode
    將 ASCII 值轉成字元


參考網址:
http://www.2cdclasses.com/?action-viewthread-tid-540 ,
http://taiwantc.com/js/js_tut_b_string0.htm