數位媒體。筆記

站內搜尋

Sunday, 23 August 2009

AS3: ColorMatrixFilter

Matrix矩陣
[a, b, c, d, e, f, g, h, i]

通常以下列形式表現
[ a, b, c,
d, e, f,
g, h, i ]

four good reasons to use the transformation matrix:
  • Skewing is not available in ActionScript outside of the transformation matrix
  • BitmapData requires a transformation matrix to transform drawn bitmaps
  • You can use a transformation matrix to encapsulate information about how to transform a MovieClip/BitmapData instance and then use it over and over again
  • You can concatenate matrices to combine their geometric effects

There are four basic ways to transform a MovieClip/BitmapData instance:

  • Translation: The values "tx" and "ty" in Figure 3 represent the x and y translation values, respectively, in pixels.
  • Scale: The values "a" and "d" represent the x and y scale values, respectively. A value of 1 indicates 100% of scale.
  • Skew: The values "b" and "c" represent the y and x skew values, respectively. A value of 0 indicates no skew, while a value of 1 indicates a skew value equal to the width or height of the object at a scale of 1.
  • Rotation: The values "a", "b", "c", and "d" can be used in combination to affect the rotation of an object. For an angle "q", rotation is achieved in the matrix by using the following values:

    a = cos(q)
    b = sin(q)
    c = –sin(q)
    d = cos(q)

e.g.
import flash.geom.Matrix;
// Scale to 200% and move to _x = 100 and _y = 50:
var m:Matrix = new Matrix( 2,0,0,2,100,50 );
clip.transform.matrix = m;

-----------------
Matrix.concat 方法
可将某个矩阵与当前矩阵连接,从而将这两个矩阵的几何效果有效地结合在一起

Additionally, the Matrix class implements methods that make it easy to apply transformation changes to the matrix. These include the following:

  • Matrix.translate(tx:Number, ty:Number)
  • Matrix.scale(sx:Number, sy:Number)
  • Matrix.rotate(angle:Number)
  • Matrix.createBox(scaleX:Number, scaleY:Number, rotation:Number, tx:Number, ty:Number)
颜色矩阵(ColorMatrixFilter)
ColorMatrixFilter accepts a 4 x 5 matrix (20-element array).


Note that the source and result values for each channel range between 0 and 255.

To change the brightness of an image, you need to change the value of each color channel by an equal amount. The simplest way to do this is to offset the source value in each channel.


Increasing the brightness


To apply matrices in Flash:(doubles the amount of green)
import flash.filters.ColorMatrixFilter;  var mat:Array = [ 1,0,0,0,0,     0,2,0,0,0,     0,0,1,0,0,     0,0,0,1,0 ]; var colorMat:ColorMatrixFilter = new ColorMatrixFilter(mat); clip.filters = [colorMat]; 
Color Matrix Demo

Wednesday, 12 August 2009

椎名林檎 - 都合のいい身体

Tuesday, 4 August 2009

String

String = Char16[] String是一組有序的Char16字元的集合。
索引如同陣列一樣,都是從0開始。並且是有length屬性的
Char16是指處於{'<>'...'<>'}之間的65536個Unicode字元

AS3中針對字元的操作:
  • charAt() - 存取目標位置的字元
  • charCodeAt() - 得到目標位置的Unicode字元的整數字元程式碼

sample:
var ddd:String = "Action";
for (var i:int = 0; ilength; i++){
trace (ddd.charAt(i) + "Unicode字元整型值為:" + ddd.charCodeAt(i) + "\t十六進位數為:" + ddd.charCodeAt(i).toString(16));
}

//注:.toString(16)意思是將數值轉換成十六進位數來表示
/*輸出:
A Unicode字元整型值為: 65 十六進位數為:41
c Unicode字元整型值為:99 十六進位數為:63
t Unicode字元整型值為:116 十六進位數為:74
i Unicode字元整型值為:105 十六進位數為:69
o Unicode字元整型值為:111 十六進位數為:6f
n Unicode字元整型值為:110 十六進位數為:6e
*/


  • fromCharCode()
sample:
ddd = String.fromCharCode(0x41, 0x53, 0x33);
trace(ddd);
//輸出:AS3

  • match() / replace() / toLowerCase() / to UpperCase()

  • search() / indexOf()
search()的參數必須是正則運算式,而indexOf()的參數只是普通字串
很多時候用indexOf()不是真的為了知道子字串的位置,而是想知道長字串有沒有包含這個子字串
如果返回-1就是沒有

  • substring() / slice() - 根據起始和終了位置來提取一個子字串
  • substr() - 根據起始位元值和長度來提取
  • split() - 根據特定的識別字將字串分隔成子字串
  • 一次輸入多行文字
使用XML和CDATA來配合
如果輸出的字串首尾有空白,可以使用mx.utils.stringUtil方法去掉
import mx.utils.stringUtil;
myString = StringUtil.trim(myString);


Friday, 31 July 2009

fl.display.Sprite

A Sprite object is similar to a movie clip, but does not have a timeline.
Sprite 可以理解为没有时间轴的 MovieClip 。
AS3的類如果想使用 MovieClip 的事件或方法必须让它继承(extends) MovieClip 或者 Sprite 。

Sunday, 26 July 2009

AS3: Getter and Setter

setter和getter的妙用
A、setter或者getter一个不是普通的成员变量,假定某类中有一个sprite,我们总是要在类内部获取该sprite的高、宽,每次都***.width, ***.height岂不是很累,我们可以

private function get XXX():Number{return ***.width};

以后直接XXX即可,代码看起来也要舒服很多。

B、setter不一定要和某成员变量联系起来,譬如

public function set data(...)...

我们可以在set中做很多工作,譬如把data转换为我们需要的数据,根据数据刷新显示等等,不一定是要有一个data属性与之相对应!

其实用private+ getter setter是为了增强封装性!
你想,如果把变量暴露给外部使用,假如后期,需求
上要对这个变量先进行些处理,那你就得改N个你
调用它的地方,而如果是用了getter和setter,那你
只要改这两个方法就可以 ...

from: 学AS3的那些破事


example:
package
{
import flash.display.Sprite;
import flash.text.TextField;

public class Starter_13 extends Sprite
{
private var tsecField:TextField;
private var tField:TextField;
public function Starter_13 ()
{
myTest();
}
private function myTest():void
{
var a:Testvar = new Testvar();

tField = new TextField();
tField.autoSize = "left";
tField.background = true;
tField.border = true;
a.mynewVar = "This is the new var.";
tField.text = "Test is: "+a.myVar;
addChild(tField);
}
}
}
import flash.display.Sprite;
import flash.text.TextField;
class Testvar extends Sprite
{
public var test:String;
public function Testvar()
{
}
public function set mynewVar(newTest:String):void
{
test = newTest;
}
public function get myVar():String
{
return test;
}
}


from: flashscript.biz