2010年12月31日 星期五

flash.utils套件__getQualifiedClassName()函數、getQualifiedSuperclassName()函數

getQualifiedClassName()函數
public function getQualifiedClassName(value:*):String
傳回物件的完整類別名稱。
參數
value:* — 需要完整限定類別名稱的物件。 任何可能傳遞至此方法的 ActionScript 值,包括所有可用的 ActionScript 類型、物件實體、基本類型 (如 uint) 及類別物件。
傳回值
String — 包含完整限定類別名稱的字串。

getQualifiedSuperclassName()函數
public function getQualifiedSuperclassName(value:*):String
參數
value:* — 任何值。
傳回值
String — 完整基底類別名稱,不存在基底類別時則為 null。


991230_flash.utils__getQualifiedClassName.swf




//
trace("類別名稱 - getQualifiedClassName(this)  :  " + getQualifiedClassName(this)); 
t1.text = "類別名稱 - getQualifiedClassName(this)  :  " + getQualifiedClassName(this);
//
var _mc:MovieClip = new MovieClip();
with (_mc.graphics)
{
 beginFill(0xddaa00, 1);
 drawCircle(130,170,50);
 endFill();
}
addChild(_mc);
addChild(t4);
//
trace("_mc所屬類別名稱 - getQualifiedClassName(_mc)  :  " + getQualifiedClassName(_mc));
trace("_mc所屬類別之父類別名稱 - getQualifiedSuperclassName(_mc)  :  " + getQualifiedSuperclassName(_mc)); 
t2.text = "_mc所屬類別名稱 - getQualifiedClassName(_mc)  :  " + getQualifiedClassName(_mc);
t3.text = "_mc所屬類別之父類別名稱 - getQualifiedSuperclassName(_mc)  :  " + getQualifiedSuperclassName(_mc);

Stage --- MainTimeline ---

991208_Stage_numChild_1.swf
91208_Stage_numChild_1.fla




trace("實體名稱 - name:" + name); // root1
trace("類別名稱 - getQualifiedClassName(this):" + getQualifiedClassName(this)); // _991208_Stage_numChild_1_fla::MainTimeline
trace("父類別名稱 - getQualifiedSuperclassName(this):" + getQualifiedSuperclassName(this)); // flash.display::MovieClip
trace("stage:" + stage); // [object Stage]
trace("Stage:" + Stage); // [class Stage]
trace("stage.stageWidth:" + stage.stageWidth); // 550
trace("stage.numChildren:" + stage.numChildren); // 1 ← stage只有一個子物件,即MainTimeline

//*** stage物件 - 主時間軸 - 主場景上有兩個實體 aaa & bbb ,aaa有 3 個子物件 ***
//一旦播放FLASH影片,將自動建立stage物件, 接著自動建立第一個相關成員,也就是「主要時間軸」
//stage.getChildAt(0).name ---> 將得到自動賦予的主時間軸的實體名稱root1,但這instance無法被操作

trace("stage.getChildAt(0).name:" + stage.getChildAt(0).name); // root1
trace("------------------------"); 

trace("this:" + this); // [object MainTimeline]
trace("root:" + root); // [object MainTimeline]
trace("root.name:" + root.name); // root1
trace("this.name:" + this.name); // root1
trace("this.numChildren:" + this.numChildren); // 2
trace("this.getChildAt(0).name:" + this.getChildAt(0).name); // aaa
trace("------------------------");

trace("aaa.numChildren:" + aaa.numChildren); // 3
trace("aaa.getChildAt(2).name:" + aaa.getChildAt(2).name); // instance5
trace("------------------------");

trace("root.parent:" + root.parent); // [object Stage]
trace("this.parent:" + this.parent); // [object Stage]
trace("root.parent.root:" + root.parent.root); // [object Stage]
trace("root.parent.getChildAt(0):" + root.parent.getChildAt(0)); //[object MainTimeline]
trace("root.parent.getChildAt(0).name:" + root.parent.getChildAt(0).name); //root1

2010年12月27日 星期一

Tweener●_bezier - 延著貝茲曲線路徑移動




import caurina.transitions.Tweener;
import caurina.transitions.properties.CurveModifiers;
import flash.display.MovieClip;
import flash.display.Sprite;
import flash.events.MouseEvent;

CurveModifiers.init();

//
var _mc:MovieClip = new MovieClip();
with (_mc.graphics)
{
 beginFill(0xddaa00, 1);
 drawCircle(20,20,36);
 endFill();
}
addChild(_mc);

//
tween_1();
//
function tween_1():void
{
 Tweener.addTween(_mc,
 {
 x:480,
 y:100, 
 _bezier:{x:250, y:600},
 delay:0.5,
 time:1.5,
 scaleX:1.5,
 scaleY:1.5,
 transition:"easeInOutQuint",
 onComplete:tween_2
 }
 );
}

//
function tween_2():void
{
 Tweener.addTween(_mc,
 {
 x:30,
 y:30, 
 _bezier:{x:300, y:400},
 delay:0.5,
 time:3,
 scaleX:1,
 scaleY:1,
 transition:"easeInOutQuint",
 onComplete:tween_1
 }
 );
}

addChild(click_mc);
click_mc.buttonMode = true;
click_mc.flag = true;
click_mc.addEventListener(MouseEvent.CLICK, removeBall);
function removeBall(e:MouseEvent):void{
 if(click_mc.flag){
  removeChild(_mc);
  click_mc.flag = false;
 }else{
  addChild(_mc);
  click_mc.flag = true;
 }
 
}

2010年12月25日 星期六

DisplayObject.mask屬性 + MouseEvent.MOUSE_WHEEL事件 + MouseEvent.delta屬性

↓ 最好點擊此連結至新視窗瀏覽,以避免滾動滑鼠滾輪時,受此頁面捲軸捲動之干擾
991224_DisplayObject.mask.swf




import flash.text.TextField;
import flash.display.Sprite;
import flash.events.MouseEvent;
import flash.text.TextFormat;

//
var format:TextFormat = new TextFormat();
with(format){
 color = 0xbbbbbb;
 size = 18;
 bold= true;
}
//
var tf:TextField = new TextField();
with(tf){
 defaultTextFormat = format;
 text = "I know I know, Keith’s probably shaking his head right now (because I continue to make apps for the Apple products) and right now I’m beyond pissed off. I submitted the update to Shell Shock (paid, then free version – in that order) to the review queue on Nov 17th. The FREE version, which was submitted AFTER the paid version, was reviewed in 30 minutes and approved. The Paid version FINALLY went into review last Wednesday ( 2weeks later ) and has been there ever since… IN REVIEW. Then I received a notice that apple needed more time to review my app. I asked “why?” – and got the customary form letter back. I asked “Why?” again, and again, I got a form letter back. So I’ve written another email today (another rant) and am now asking for a phone number or someone I can actually “talk” to at Apple. I doubt they’ll pony up that information btw. Seems crazy that I’m giving them 30% and bending over backwards to cater to “their” ideals when it comes to creating the software, but when it comes to *my* ideals (you know, crazy stuff like approvals in a reasonable amount of time and IN ORDER that they were submitted), they’re ignoring me (duh, what else is new) So, is there anyone out there with a phone number or email contact that I don’t already know about that I can call and complain?";
 multiline = true;
 wordWrap = true;
 width = 550;
 autoSize = TextFieldAutoSize.LEFT;
 selectable = false;
}

addChild(tf);

//
var myCircle:Sprite = new Sprite();
var radius:int = 150;
var posX:int = stage.stageWidth/2;
var posY:int = stage.stageHeight/2;

//
//beginFill(color:uint, alpha:Number = 1.0):void
//指定簡單的單色填色,後續在繪製時呼叫其它 Graphics 方法 (例如 lineTo() 或 drawCircle()) 便可以使用此填色
with(myCircle.graphics){
 beginFill(0xff0000, 1.0); 
 drawCircle(posX,posY,radius);
 endFill();
}
//
addChild(myCircle);
//開啟按鈕模式
myCircle.buttonMode = true;
//不用手形指標
//myCircle.useHandCursor = false;

//
addChild(txt);
//

myCircle.addEventListener(MouseEvent.MOUSE_DOWN, beginDrag);
myCircle.addEventListener(MouseEvent.MOUSE_UP, endDrag);
stage.addEventListener(MouseEvent.MOUSE_WHEEL, wheel);
//
function beginDrag(e:MouseEvent = null):void{
 tf.mask = myCircle;
 e.currentTarget.startDrag();
}
//
function endDrag(e:MouseEvent = null):void{
 tf.mask = null;
 e.currentTarget.stopDrag();
}
//
function wheel(e:MouseEvent):void{
 //
 stage.focus = myCircle;
 trace(e.delta);
 radius += (e.delta)*4;
 with(myCircle.graphics){
  clear();
  beginFill(0xff0000, 1.0); 
  drawCircle(posX,posY,radius);
  endFill();
 }
}

2010年12月23日 星期四

[AS3] ColorMatrixFilter.clone()方法 - 傳回此濾鏡物件的副本

ColorMatrixFilter.clone();
clone():BitmapFilter - clone()方法傳回值為BitmapFilter物件
[覆寫] 傳回此濾鏡物件的副本。

● 點擊[click]按鈕,拷貝左圖的ColorMatrixFilter物件,到右圖套用同樣濾境效果。

991223_ColorMatrixFilter.clone_1.swf



package  {
 import flash.display.Sprite;
 import flash.filters.ColorMatrixFilter;
 import flash.display.BitmapData;
 import flash.display.Bitmap;
 import flash.filters.BitmapFilter;
 import flash.display.DisplayObject;
 import flash.events.Event;
 import flash.events.MouseEvent;

 //
 public class ColorMatrixFilter_clone_991223_1 extends Sprite{
  //
  public var bmd1:BitmapData = new MyPhoto1(0,0);
  public var bm1:Bitmap = new Bitmap(bmd1);
  public var bmd2:BitmapData = new MyPhoto2(0,0);
  public var bm2:Bitmap = new Bitmap(bmd2);
  //
  public var myFilter1:ColorMatrixFilter;
  //
  public function ColorMatrixFilter_clone_991223_1() {
   addChild(bm1);
   addChild(bm2);
   addChild(click_mc);
   with(bm1){
    scaleX = 0.4;
    scaleY = 0.4;
    x = 40;
    y = 50;
   }
   with(bm2){
    scaleX = 0.4;
    scaleY = 0.4;
    x = 290;
    y = 50;
   }
   
   firstMat();
   click_mc.addEventListener(MouseEvent.CLICK, cloneMat);
   click_mc.buttonMode = true;
  }
  //
  public function firstMat():void{
   var matrix1:Array = new Array();
   matrix1 = matrix1.concat([0, 0, 1.5, 0, 0]); //RED Channel
   matrix1 = matrix1.concat([0, 1.5, 0, 0, 0]); //GREEN Channel
   matrix1 = matrix1.concat([1.5, 0, 0, 0, 0]); //BLUE Channel
   matrix1 = matrix1.concat([0, 0, 0, 1, 0]); //ALPHA Channel
   myFilter1 = new ColorMatrixFilter(matrix1);
   bm1.filters = [myFilter1]; 
  }
  //
  public function cloneMat(e:Event = null){
   //ColorMatrixFilter.clone();
   //clone():BitmapFilter - clone()方法傳回值為BitmapFilter物件
   //[覆寫] 傳回此濾鏡物件的副本。
   var myFilter2:BitmapFilter = myFilter1.clone();
   bm2.filters = [myFilter2];
  }

 }
 
 
}

[AS3] flash.filter.ColorMatrixFilter(matrix) - matrix變形矩陣改變對比(contrast)

原圖:


參考此篇處理方式:
UNDERSTANDING AS3 COLORMATRIXFILTER CLASS



● 提高點陣圖對比(contrast)

991223_ColorMF_contrast1.swf





package  {
 import flash.display.Sprite;
 import flash.filters.ColorMatrixFilter;
 import flash.display.BitmapData;
 import flash.display.Bitmap;
 import flash.display.DisplayObject;
 //
 public class ColorMF_contrast1_991223 extends Sprite{
  public var bmd:BitmapData = new MyPhoto(0,0);
  public var bm:Bitmap = new Bitmap(bmd);
  public function ColorMF_contrast1_991223() {
   addChild(bm);
   var matrix:Array = new Array();
   matrix = matrix.concat([2, 0, 0, 0, -40]); //RED Channel
   matrix = matrix.concat([0, 2, 0, 0, -40]); //GREEN Channel
   matrix = matrix.concat([0, 0, 2, 0, -40]); //BLUE Channel
   matrix = matrix.concat([0, 0, 0, 1, 0]); //ALPHA Channel
   var myFilter:ColorMatrixFilter = new ColorMatrixFilter(matrix);
   bm.filters = [myFilter];
  }

 }
}

2010年12月22日 星期三

[AS3] flash.filter.ColorMatrixFilter(matrix) - matrix變形矩陣改變飽合度(saturation)

變形矩陣示意圖



原圖:將被提升色彩飽合度。


參考此篇處理方式:
UNDERSTANDING AS3 COLORMATRIXFILTER CLASS

991221_ColorMF_saturation.swf  - ↓ 以下 swf 檔色彩飽合度已提升。





package  {
 import flash.display.Sprite;
 import flash.filters.ColorMatrixFilter;
 import flash.display.BitmapData;
 import flash.display.Bitmap;
 import flash.display.DisplayObject;
 //
 public class ColorMF_saturation_991221 extends Sprite{
  public var bmd:BitmapData = new MyPhoto(0,0);
  public var bm:Bitmap = new Bitmap(bmd);
  public function ColorMF_saturation_991221() {
   addChild(bm);
   var matrix:Array = new Array();
   matrix = matrix.concat([2, -1, 0, 0, 0]); //RED Channel
   matrix = matrix.concat([-1, 2, 0, 0, 0]); //GREEN Channel
   matrix = matrix.concat([0, -1, 2, 0, 0]); //BLUE Channel
   matrix = matrix.concat([0, 0, 0, 1, 0]); //ALPHA Channel
   var myFilter:ColorMatrixFilter = new ColorMatrixFilter(matrix);
   bm.filters = [myFilter];
  }

 }
 
}




參考此篇處理方式:Matrix Operations for Image Processing - Paul Haeberli




991221_ColorMF_saturation2.swf

● s = 1 ← 點陣圖為原值




991221_ColorMF_saturation2a.swf

● s = 1.8 或 大於1 ← 點陣圖色彩飽合度增加




991221_ColorMF_saturation2b.swf

● s = 0 ← 點陣圖變成灰階




991221_ColorMF_saturation2c.swf

● s = 0 ← 點陣圖變成互補色





package  {
 import flash.display.Sprite;
 import flash.filters.ColorMatrixFilter;
 import flash.display.BitmapData;
 import flash.display.Bitmap;
 import flash.display.DisplayObject;
 //
 public class ColorMF_saturation2_991221 extends Sprite{
  public var bmd:BitmapData = new MyPhoto(0,0);
  public var bm:Bitmap = new Bitmap(bmd);
  public function ColorMF_saturation2_991221() {
   addChild(bm);
   //
   var rwgt:Number = 0.3086;
   var gwgt:Number = 0.6094;
   var bwgt:Number = 0.0802;
   //
   var s:Number = 1;
   //
   var a:Number = (1.0-s)*rwgt + s;
      var b:Number = (1.0-s)*gwgt;
      var c:Number = (1.0-s)*bwgt;
      var d:Number = (1.0-s)*rwgt;
      var e:Number = (1.0-s)*gwgt + s;
      var f:Number = (1.0-s)*bwgt;
      var g:Number = (1.0-s)*rwgt;
      var h:Number = (1.0-s)*gwgt;
      var i:Number = (1.0-s)*bwgt + s;
   //
   var matrix:Array = new Array();
   matrix = matrix.concat([a, b, c, 0, 0]); //RED Channel
   matrix = matrix.concat([d, e, f, 0, 0]); //GREEN Channel
   matrix = matrix.concat([g, h, i, 0, 0]); //BLUE Channel
   matrix = matrix.concat([0, 0, 0, 1, 0]); //ALPHA Channel
   var myFilter:ColorMatrixFilter = new ColorMatrixFilter(matrix);
   bm.filters = [myFilter];
  }

 }
 
}

2010年12月21日 星期二

[AS3] flash.filter.ColorMatrixFilter(matrix) - matrix變形矩陣改變色相(hue)

原圖~



matrix變形矩陣原值,此值忠於原圖,不會改變原圖的色相、飽合度、明度等。



matrix變形矩陣改值例子:交換RGB三色Channel的內容,及修改其數值大小與正負,可改變 Bitmap 物件(點陣圖) 色相(hue)


991221_ColorMF_hue.swf




package  {
 import flash.display.Sprite;
 import flash.filters.ColorMatrixFilter;
 import flash.display.BitmapData;
 import flash.display.Bitmap;
 import flash.display.DisplayObject;
 //
 public class ColorMF_hue_991221 extends Sprite{
  public var bmd:BitmapData = new MyPhoto(0,0);
  public var bm:Bitmap = new Bitmap(bmd);
  public function ColorMF_hue_991221() {
   addChild(bm);
   var matrix:Array = new Array();
   matrix = matrix.concat([0, 0, 1, 0, 0]); //RED Channel
   matrix = matrix.concat([0, 1, 0, 0, 0]); //GREEN Channel
   matrix = matrix.concat([1, 0, 0, 0, 0]); //BLUE Channel
   matrix = matrix.concat([0, 0, 0, 1, 0]); //ALPHA Channel
   var myFilter:ColorMatrixFilter = new ColorMatrixFilter(matrix);
   bm.filters = [myFilter];
  }

 }
 
}

[AS3] 使用matrix顏色變形矩陣操作Bitmap物件,使其為原值,圖形RGB不變



matrix[0]、matrix[6]、matrix[12] 值皆為1時,Bitmap物件為原值,圖形不變。




package  {
 import flash.display.Sprite;
 import flash.filters.ColorMatrixFilter;
 import flash.display.BitmapData;
 import flash.display.Bitmap;
 import flash.display.DisplayObject;
 //
 public class ColorMF_identity_991221 extends Sprite{
  public var bmd:BitmapData = new MyPhoto(0,0);
  public var bm:Bitmap = new Bitmap(bmd);
  public function ColorMF_identity_991221() {
   addChild(bm);
   var matrix:Array = new Array();
   matrix = matrix.concat([1, 0, 0, 0, 0]); //RED Channel
   matrix = matrix.concat([0, 1, 0, 0, 0]); //GREEN Channel
   matrix = matrix.concat([0, 0, 1, 0, 0]); //BLUE Channel
   matrix = matrix.concat([0, 0, 0, 1, 0]); //ALPHA Channel
   var myFilter:ColorMatrixFilter = new ColorMatrixFilter(matrix);
   bm.filters = [myFilter];
  }

 }
 
}

2010年12月18日 星期六

[AS3] flash.filter.ColorMatrixFilter(matrix) - RGB到灰階

ColorMatrixFilter () 建構函式
public function ColorMatrixFilter(matrix:Array = null)
DisplayObject.filters = ColorMatrix 陣列物件
索引的陣列,其中包含目前和顯示物件相關的每個濾鏡物件。

適用於 Adobe Flash Professional CS5 的 ActionScript 3.0 參考__●flash.filters.ColorMatrixFilter類別
適用於 Adobe Flash Professional CS5 的 ActionScript 3.0 參考__●flash.filters.ColorMatrixFilter.matrix屬性
適用於 Adobe Flash Professional CS5 的 ActionScript 3.0 參考__●flash.display.DisplayObject.filters屬性

原圖:將在Flash中處理成灰階。




參考此篇處理方式:
UNDERSTANDING AS3 COLORMATRIXFILTER CLASS

991217_ColorMF_1.swf





package  {
 import flash.display.Sprite;
 import flash.display.BitmapData;
 import flash.filters.ColorMatrixFilter;
 import flash.display.Bitmap;
 import flash.display.DisplayObject;

 public class ColorMF_991217 extends Sprite{
  var photo1:BitmapData = new MyPhoto(0,0);
  var bm:Bitmap = new Bitmap(photo1);
  public function ColorMF_991217() {
   addChild(bm);
   var matrix:Array = new Array();
   matrix = matrix.concat([0.5, 0.5, 0.5, 0, 0]);
   matrix = matrix.concat([0.5, 0.5, 0.5, 0, 0]);
   matrix = matrix.concat([0.5, 0.5, 0.5, 0, 0]);
   matrix = matrix.concat([0, 0, 0, 1, 0]);
   var myFilter:ColorMatrixFilter = new ColorMatrixFilter(matrix);
   DisplayObject(bm).filters = [myFilter];
  }

 }
 
}





參考此篇處理方式:Matrix Operations for Image Processing - Paul Haeberli

991217_ColorMF_2.swf





package  {
 import flash.display.Sprite;
 import flash.display.BitmapData;
 import flash.filters.ColorMatrixFilter;
 import flash.display.Bitmap;
 import flash.display.DisplayObject;

 public class ColorMF2_991217 extends Sprite{
  var photo1:BitmapData = new MyPhoto(0,0);
  var bm:Bitmap = new Bitmap(photo1);
  public function ColorMF2_991217() {
   addChild(bm);
   //matrix 變形矩陣 - 灰階處理
   var matrix:Array = new Array();
   var rwgt:Number = 0.3086;
   var gwgt:Number = 0.6094;
   var bwgt:Number = 0.0802;
   matrix = matrix.concat([rwgt, gwgt, bwgt, 0, 0]);
   matrix = matrix.concat([rwgt, gwgt, bwgt, 0, 0]);
   matrix = matrix.concat([rwgt, gwgt, bwgt, 0, 0]);
   matrix = matrix.concat([0, 0, 0, 1, 0]);
   //ColorMatrixFilter建構式,以指定的參數 matrix 初始化新的 ColorMatrixFilter 實體。
   var myFilter:ColorMatrixFilter = new ColorMatrixFilter(matrix);
   //DisplayObject(bm).filters = [myFilter];
   //DisplayObject物件的filter屬性參照所有濾鏡組成的陣列
   bm.filters = [myFilter];
   trace(myFilter.matrix);
   trace(myFilter);
  }

 }
 
}

2010年12月16日 星期四

在BitmapData上套用Blur模糊濾鏡 - BitmapData.applyFilter()方法 + flash.filters.BlurFilter()建構函式




套用濾鏡前原圖




import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.geom.Point;
import flash.geom.Rectangle;
import flash.filters.BlurFilter;

//建構元件庫中 MyPhoto1 內嵌資源類別的實體,指定給BitmapData類型的變數。
//MyPhoto1類別的基底類別為flash.display.BitmapData類別
var bmd1:BitmapData = new MyPhoto1(0,0);

//Rectangle()建構函式
//public function Rectangle(x:Number = 0, y:Number = 0, width:Number = 0, height:Number = 0)
//x 和 y 參數指定左上角座標,width 和 height 參數指定矩形寬高,以建立新的 Rectangle 物件。
//若呼叫這個函數時沒有使用參數,則會建立 x、y、width 和 height 屬性都設為 0 的矩形。

//建立矩形物件,寬高設為550,400,以符合swf檔案及bmd1點陣圖資料寬高尺寸
//這矩行物件rect將作為applyFilter()之參數
var rect:Rectangle = new Rectangle(0, 0, 550, 400);

//Point(x:Number = 0, y:Number = 0)
//建立新的點。如果沒有將 x, y 參數傳遞給這個方法,則會在 (0,0) 建立一個點。
//Point 物件代表二維座標系統中的位置,其中 x 表示水平軸,而 y 表示垂直軸。
var pt:Point = new Point(0, 0);

//宣告blurX和blurY變數及其值,將做為applyFilter()的模糊參數
var blurX:Number = 40;
var blurY:Number = 5;

//
//BlurFilter()建構函式
//public function BlurFilter(blurX:Number = 4.0, blurY:Number = 4.0, quality:int = 1)

//BitmapFilterQuality.HIGH、BitmapFilterQuality.MEDIUM、BitmapFilterQuality.LOW
var filter:BlurFilter = new BlurFilter(blurX, blurY, BitmapFilterQuality.HIGH);

//applyFilter()方法
//public function applyFilter(sourceBitmapData:BitmapData, sourceRect:Rectangle, destPoint:Point, filter:BitmapFilter):void
bmd1.applyFilter(bmd1, rect, pt, filter);

//建構Bitmap物件以顯示BitmapData物件
var bm1:Bitmap = new Bitmap(bmd1);
addChild(bm1);



2010年12月15日 星期三

ActionScript 3.0 類別物件


學習 ActionScript 3.0_使用 ActionScript 設計物件導向程式_進階主題__ActionScript 3.0 類別物件

2010年12月13日 星期一

[AS3] BitmapData.merge()方法 - 從來源影像到目標影像的每個色版的混合

merge(sourceBitmapData:BitmapData, sourceRect:Rectangle, destPoint:Point, redMultiplier:uint, greenMultiplier:uint, blueMultiplier:uint, alphaMultiplier:uint):void
執行從來源影像到目標影像的每個色版的混合。

適用於 Adobe Flash Professional CS5 的 ActionScript 3.0 參考__●flash.display.BitmapData.merge()方法


(一)

991213_BitmapData.merge_1.swf



import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.geom.Rectangle;
import flash.geom.Point;

var bmd1:BitmapData = new BitmapData(100, 80, true, 0xFF00FF00);
var bmd2:BitmapData = new BitmapData(100, 80, true, 0xFFFF0000);
var rect:Rectangle = new Rectangle(0, 0, 20, 20);
var pt:Point = new Point(20, 20);
var mult:uint = 0x80; // 50% 
bmd1.merge(bmd2, rect, pt, mult, mult, mult, mult);

var bm1:Bitmap = new Bitmap(bmd1);
addChild(bm1);
var bm2:Bitmap = new Bitmap(bmd2);
addChild(bm2);
bm2.x = 110;


(二)

 

991213_BitmapData.merge_2.swf



import flash.display.BitmapData;
import flash.display.Bitmap;
import flash.geom.Rectangle;
import flash.geom.Point;

//
var bmd1:BitmapData = new MyPhoto1(0, 0);
var bmd2:BitmapData = new MyPhoto2(0, 0);
//
var rect:Rectangle = new Rectangle(100, 100, 450, 300);
var pt:Point = new Point(50, 50);
var multiplier:uint = 0x80;
//
bmd1.merge(bmd2, rect, pt, 0xf0, 0xa0, 0x20, 0x30);
//
var bm1:Bitmap = new Bitmap(bmd1);
bm1.x = 0;
bm1.y = 0;
/*
var bm2:Bitmap = new Bitmap(bmd2);
bm2.x = 0;
bm2.y = 0;
*/
//
addChild(bm1);
//addChild(bm2);

BitmapData.noise() - 以隨機雜點在影像上填色

noise(randomSeed:int, low:uint = 0, high:uint = 255, channelOptions:uint = 7, grayScale:Boolean = false):void
以呈現隨機雜點的像素來填色影像。
MAX_VALUE 常數
public static const MAX_VALUE:int = 2147483647
可表示之 32 位元的最大具有正負號整數,也就是 2,147,483,647。

適用於 Adobe Flash Professional CS5 的 ActionScript 3.0 參考__●flash.display.BitmapData.noise()

適用於 Adobe  Flash  Professional CS5 的 ActionScript  3.0 參考___最上層_int_公用常數__●MAX_VALUE常數


(一)填色BitmapData物件

991213_BitmapData.noise_1.swf



import flash.display.BitmapData;
import flash.display.Bitmap;

//
var bmd:BitmapData = new BitmapData(450, 290);
var thisSeed:int = int(Math.random()*int.MAX_VALUE);
//
bmd.noise(thisSeed, 0, 255, BitmapDataChannel.RED | BitmapDataChannel.BLUE | BitmapDataChannel.GREEN | BitmapDataChannel.ALPHA, false);
//
var bm:Bitmap = new Bitmap(bmd);
bm.x = 50;
bm.y = 50;
addChild(bm);


主場景背景色改為#FF6600
bmd.noise(thisSeed, 0, 255, BitmapDataChannel.RED | BitmapDataChannel.BLUE | BitmapDataChannel.ALPHA, false);

991213_BitmapData.noise_1a.swf



主場景背景色改為#663333
bmd.noise(thisSeed, 0, 255, BitmapDataChannel.RED | BitmapDataChannel.BLUE | BitmapDataChannel.ALPHA, true);
→ grayScale參數改成true,會將所有顏色色版設為相同值以建立灰階影像。 將此參數設為 true 不會影響所選取的 Alpha 色版。

991213_BitmapData.noise_1a.swf




(二)元件庫中點陣圖內建資源類別,以new運算子實體化,指定給BitmapData類型變數bmd。在此點陣圖素bmd上執行nois()方法。

未執行nois()方法前

991213_BitmapData.noise_2a.swf



執行nois()方法
bmd.noise(thisSeed, 0, 255, BitmapDataChannel.RED | BitmapDataChannel.BLUE | BitmapDataChannel.ALPHA, false);

991213_BitmapData.noise_2b.swf



import flash.display.BitmapData;
import flash.display.Bitmap;

//
var bmd:BitmapData = new MyPhoto(550, 300);
var thisSeed:int = int(Math.random()*int.MAX_VALUE);
//
bmd.noise(thisSeed, 0, 255, BitmapDataChannel.RED | BitmapDataChannel.BLUE | BitmapDataChannel.ALPHA, false);
//
var bm:Bitmap = new Bitmap(bmd);
bm.x = -100;
bm.y = -100;
addChild(bm);

2010年12月12日 星期日

[AS3] BitmapData.getPixel32()

getPixel32(x:int, y:int):uint
傳回 ARGB 顏色數值,其中包含 Alpha 色版資料和 RGB 資料

[AS3] BitmapData.getPixel()方法 - 擷取BitmapData 物件特定點 (x, y) 上 的 RGB 像素值

getPixel(x:int, y:int):uint
傳回整數,代表 BitmapData 物件中特定點 (x, y) 的 RGB 像素值。
toString(radix:uint):String
傳回 int 物件的字串形式。
 radix:uint — 會指定用於數字到字串轉換的底數 (從 2 到 36)。 如果您並未指定 radix 參數,預設值會是 10。

(例一)
深藍色為主場景背景色。

左上角 300x200 大小的 0xaabbff 色塊為 BitmapData 物件所定義:
var bmData:BitmapData = new BitmapData(300, 200, true, 0xffaabbff);
 ( 並透過Bitmap類別顯示在主場景(50,50)位置,即 bm.x = 50; bm.y = 50; )

以 var pixelValue:uint = bmData.getPixel(0, 0); 擷取 bmData 上座標(0,0)位置的RGB畫素值,
並指定給pixelValue。這個座標(0,0)是屬於bmData的local座標,而非主場景座標。
此時pixelValue為10進位整數。因此以 pixelValue.toString(16) 轉換與傳回 16 進位數值的字串形式。

300x200 大小的bmData物件,其座標範圍在 (0, 0) ~ (299, 199)
當使用getPixel()方法指定擷取點時,不能超過此範圍,否則會傳回 0 值 。




import flash.display.BitmapData;

//
var bmData:BitmapData = new BitmapData(300, 200, true, 0xffaabbff);
//
var pixelValue:uint = bmData.getPixel(0, 0);
trace(pixelValue.toString(16));
tf.text = pixelValue.toString(16);
//
var bm:Bitmap = new Bitmap(bmData);
bm.x = 50;
bm.y = 50;
addChild(bm);


(例二)
將元件庫中的點陣圖設定為內嵌資源類別,類別名稱為 MyPhoto,基底類別為 BitmapData。
再以 new 運算子建構 MyPhoto 實體,並指定給名為 bmData 的 BitmapData型態變數。
var bmData:BitmapData = new MyPhoto(0, 0);
此處 new MyPhoto(0, 0)的(0, 0)本應指定點陣圖類別實體的寬與高,但其實不會有作用,
bmData物件所載入的點陣圖寬高,將遵循元件庫中的圖檔寬高。

以 var pixelValue:uint = bmData.getPixel(599, 425); 擷取 bmData 上座標(599, 425)位置的RGB畫素值。




import flash.display.BitmapData;

//
var bmData:BitmapData = new MyPhoto(0, 0);
//
var pixelValue:uint = bmData.getPixel(599, 425);
trace(pixelValue.toString(16));
tf.text = pixelValue.toString(16);
//
var bm:Bitmap = new Bitmap(bmData);
//bm.width = 550;
//bm.height = 400;
bm.x = 0;
bm.y = 0;
addChild(bm);
addChild(tf);
addChild(comment);

[AS3] BitmapData.copyChannel()方法(二) - 將其它BitmapData物件的RGB三個色版,分別拷貝到本身RGB目標色版

BitmapData()建構函式
public function BitmapData(width:int, height:int, transparent:Boolean = true, fillColor:uint = 0xFFFFFFFF)
copyChannel()方法
public function copyChannel(sourceBitmapData:BitmapData, sourceRect:Rectangle, destPoint:Point, sourceChannel:uint, destChannel:uint):void

991211_BitmapData.copyChannel_2.swf





import flash.display.Loader;
import flash.net.URLRequest;
import flash.events.Event;
import flash.events.ProgressEvent;
import flash.display.BitmapData;
import flash.text.TextField;
import flash.text.TextFormat;
import flash.geom.Rectangle;
import flash.geom.Point;
import flash.display.Bitmap;

//
const bmURL:String = "991211_photo_1.jpg";
var ldr:Loader = new Loader();
ldr.load(new URLRequest(bmURL));
ldr.contentLoaderInfo.addEventListener(Event.COMPLETE, onLoaderComplete);
ldr.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, onProgress);

//
var bmData1:BitmapData;
//0xffff0000 <---ARGB色彩,A為不透明度.
var bmData2:BitmapData = new BitmapData(360, 240, true, 0xffff0000);
var bm1:Bitmap;
var bm2:Bitmap;
//
var format:TextFormat = new TextFormat();
with(format){
 color = 0xff00ff;
 size = 88;
 font = "Lucida Fax";
 bold = true;
 align = "center";
}
//
var tF:TextField = new TextField;
with(tF){
 x = 0;
 y = 150;
 width = 550;
 //autoSize = TextFieldAutoSize.LEFT;
}
tF.defaultTextFormat = format;
addChild(tF);

//
function onProgress(e:ProgressEvent):void{
 tF.text = String(Math.floor((e.bytesLoaded/e.bytesTotal*100)));
}

//
var rect:Rectangle = new Rectangle(0,0, 550, 400);
var point:Point = new Point(0, 0);
//
function onLoaderComplete(e:Event):void{
 tF.text = "";
 gogo();
}
//copyChannel()方法  
//public function copyChannel(sourceBitmapData:BitmapData, sourceRect:Rectangle, destPoint:Point, sourceChannel:uint, destChannel:uint):void
//http://help.adobe.com/zh_TW/Flash/CS5/AS3LR/flash/display/BitmapData.html#copyChannel()
function gogo(){
 bmData1 = (ldr.content as Bitmap).bitmapData;
 bmData2.copyChannel(bmData1, rect, point, BitmapDataChannel.RED, BitmapDataChannel.RED);
 bmData2.copyChannel(bmData1, rect, point, BitmapDataChannel.GREEN, BitmapDataChannel.GREEN);
 bmData2.copyChannel(bmData1, rect, point, BitmapDataChannel.BLUE, BitmapDataChannel.BLUE);
 //bm1 = new Bitmap(bmData1);
 bm2 = new Bitmap(bmData2);
 bm2.x = 60;
 bm2.y = 60;
 //addChild(bm1);
 addChild(bm2);
}



991211_BitmapData.copyChannel_2a.swf - 拷貝紅藍兩個色版色版

2010年12月11日 星期六

[AS3] BitmapData.copyChannel()方法(一) - 挑選自身或其它BitmapData物件的某色版,傳送到目標色版

copyChannel()方法
public function copyChannel(sourceBitmapData:BitmapData, sourceRect:Rectangle, destPoint:Point, sourceChannel:uint, destChannel:uint):void


991211_BitmapData.copyChannel_1.swf - 未使用copyChannel()方法,載入991211_photo_1.jpg圖檔




import flash.display.Loader;
import flash.net.URLRequest;
import flash.events.Event;
import flash.events.ProgressEvent;
import flash.display.BitmapData;
import flash.text.TextField;
import flash.text.TextFormat;
import flash.geom.Rectangle;
import flash.geom.Point;
import flash.display.Bitmap;

//
const bmURL:String = "991211_photo_1.jpg";
var ldr:Loader = new Loader();
ldr.load(new URLRequest(bmURL));
ldr.contentLoaderInfo.addEventListener(Event.COMPLETE, onLoaderComplete);
ldr.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, onProgress);

//
var bmData1:BitmapData;
//var bmData2:BitmapData;
var bm1:Bitmap;
//var bm2:Bitmap;
//
var format:TextFormat = new TextFormat();
with(format){
 color = 0xff00ff;
 size = 88;
 font = "Lucida Fax";
 bold = true;
 align = "center";
}
//
var tF:TextField = new TextField;
with(tF){
 x = 0;
 y = 150;
 width = 550;
 //autoSize = TextFieldAutoSize.LEFT;
}
tF.defaultTextFormat = format;
addChild(tF);

//
function onProgress(e:ProgressEvent):void{
 tF.text = String(Math.floor((e.bytesLoaded/e.bytesTotal*100)));
}

//
var rect:Rectangle = new Rectangle(0,0, 550, 400);
var point:Point = new Point(0, 0);
//
function onLoaderComplete(e:Event):void{
 gogo();
}
//
function gogo(){
 bmData1 = (ldr.content as Bitmap).bitmapData;
 //bmData1.copyChannel(bmData1, rect, point, BitmapDataChannel.BLUE, BitmapDataChannel.RED);
 bm1 = new Bitmap(bmData1);
 addChild(bm1);
}




991211_BitmapData.copyChannel_1a.swf - 使用copyChannel()方法,載入991211_photo_1.jpg圖檔
→ copyChannel(bmData1, rect, point, BitmapDataChannel.BLUE, BitmapDataChannel.RED);




import flash.display.Loader;
import flash.net.URLRequest;
import flash.events.Event;
import flash.events.ProgressEvent;
import flash.display.BitmapData;
import flash.text.TextField;
import flash.text.TextFormat;
import flash.geom.Rectangle;
import flash.geom.Point;
import flash.display.Bitmap;

//
const bmURL:String = "991211_photo_1.jpg";
var ldr:Loader = new Loader();
ldr.load(new URLRequest(bmURL));
ldr.contentLoaderInfo.addEventListener(Event.COMPLETE, onLoaderComplete);
ldr.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, onProgress);

//
var bmData1:BitmapData;
var bmData2:BitmapData;
var bm1:Bitmap;
var bm2:Bitmap;
//
var format:TextFormat = new TextFormat();
with(format){
 color = 0xff00ff;
 size = 88;
 font = "Lucida Fax";
 bold = true;
 align = "center";
}
//
var tF:TextField = new TextField;
with(tF){
 x = 0;
 y = 150;
 width = 550;
 //autoSize = TextFieldAutoSize.LEFT;
}
tF.defaultTextFormat = format;
addChild(tF);

//
function onProgress(e:ProgressEvent):void{
 tF.text = String(Math.floor((e.bytesLoaded/e.bytesTotal*100)));
}

//
var rect:Rectangle = new Rectangle(0,0, 550, 400);
var point:Point = new Point(0, 0);
//
function onLoaderComplete(e:Event):void{
 gogo();
}
//
function gogo(){
 bmData1 = (ldr.content as Bitmap).bitmapData;
 bmData1.copyChannel(bmData1, rect, point, BitmapDataChannel.BLUE, BitmapDataChannel.RED);
 bm1 = new Bitmap(bmData1);
 addChild(bm1);
}




991211_BitmapData.copyChannel_1b.swf - 使用copyChannel()方法,載入991211_photo_1.jpg圖檔
→ bmData1.copyChannel(bmData1, rect, point, BitmapDataChannel.RED, BitmapDataChannel.BLUE);




import flash.display.Loader;
import flash.net.URLRequest;
import flash.events.Event;
import flash.events.ProgressEvent;
import flash.display.BitmapData;
import flash.text.TextField;
import flash.text.TextFormat;
import flash.geom.Rectangle;
import flash.geom.Point;
import flash.display.Bitmap;

//
const bmURL:String = "991211_photo_1.jpg";
var ldr:Loader = new Loader();
ldr.load(new URLRequest(bmURL));
ldr.contentLoaderInfo.addEventListener(Event.COMPLETE, onLoaderComplete);
ldr.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, onProgress);

//
var bmData1:BitmapData;
var bmData2:BitmapData;
var bm1:Bitmap;
var bm2:Bitmap;
//
var format:TextFormat = new TextFormat();
with(format){
 color = 0xff00ff;
 size = 88;
 font = "Lucida Fax";
 bold = true;
 align = "center";
}
//
var tF:TextField = new TextField;
with(tF){
 x = 0;
 y = 150;
 width = 550;
 //autoSize = TextFieldAutoSize.LEFT;
}
tF.defaultTextFormat = format;
addChild(tF);

//
function onProgress(e:ProgressEvent):void{
 tF.text = String(Math.floor((e.bytesLoaded/e.bytesTotal*100)));
}

//
var rect:Rectangle = new Rectangle(0,0, 600, 450);
var point:Point = new Point(-50, -50);
//
function onLoaderComplete(e:Event):void{
 gogo();
}
//
function gogo(){
 bmData1 = (ldr.content as Bitmap).bitmapData;
 bmData1.copyChannel(bmData1, rect, point, BitmapDataChannel.RED, BitmapDataChannel.BLUE);
 bm1 = new Bitmap(bmData1);
 addChild(bm1);
}




參閱適用於 Adobe Flash Professional CS5 的 ActionScript 3.0 參考 - Flash Help關於BitmapData.copyChannel()的資訊

2010年12月10日 星期五

[AS3] 由Bitmap類別實體的bitmapData屬性參照BitmapData物件,以其fillRect()方法在點陣像素上繪製矩形填色

BitmapData()建構函式
public function BitmapData(width:int, height:int, transparent:Boolean = true, fillColor:uint = 0xFFFFFFFF)
BitmapData.fillRect()方法public function fillRect(rect:Rectangle, color:uint):void
Rectangle()建構函式
public function Rectangle(x:Number = 0, y:Number = 0, width:Number = 0, height:Number = 0)


991210_BitmapData_fillRect_1.swf



//
import flash.display.BitmapData;
import flash.display.Bitmap;
import flash.geom.Rectangle;

//
//BitmapData()建構函式
//public function BitmapData(width:int, height:int, transparent:Boolean = true, fillColor:uint = 0xFFFFFFFF)
var bmpData:BitmapData = new BitmapData(420, 320, true, 0xff6600ff);
var bitmap:Bitmap = new Bitmap(bmpData);
bitmap.x = 50;
bitmap.y = 50;
addChild(bitmap);

//
//Rectangle()建構函式
//public function Rectangle(x:Number = 0, y:Number = 0, width:Number = 0, height:Number = 0)
var rect1:Rectangle = new Rectangle(50, 120 ,20, 20);
for(var i:int=0; i<7; i++){
 //fillRect()方法  
 //public function fillRect(rect:Rectangle, color:uint):void
 //由Bitmap類別實體的bitmapData屬性參照BitmapData物件,
 //以其fillRect()方法在點陣像素上繪製矩形填色
 bitmap.bitmapData.fillRect(rect1, 0xffffffff);
 rect1.x += 20;
 rect1.y += 20;
}
//
var rect2:Rectangle = new Rectangle(170, 240 ,20, 20);
for(var j:int=0; j<12; j++){
 bitmap.bitmapData.fillRect(rect2, 0xffffffff);
 rect2.x += 20;
 rect2.y -= 20;
}

[AS3] 將Loader類別所載入外部點陣圖BitmapData資料轉植至新建的Bitmap類別實體

Bitmap()建構函式
public function Bitmap(bitmapData:BitmapData = null, pixelSnapping:String = "auto", smoothing:Boolean = false)
new Bitmap((Loader.content as Bitmap).bitmapData);

991210_BitmapData_1.swf



import flash.display.Loader;
import flash.net.URLRequest;
import flash.events.Event;
import flash.display.Bitmap;

//
const bmpURL:String = "991210_1.jpg";
//
var ldr:Loader = new Loader();
ldr.load(new URLRequest(bmpURL));
ldr.contentLoaderInfo.addEventListener(Event.COMPLETE, bmpWork);
//
var showBmp1:Bitmap;
var showBmp2:Bitmap;
//
function bmpWork(e:Event):void{
 //
 var ldrBmp:Bitmap = ldr.content as Bitmap;
 //
 showBmp1 = new Bitmap(ldrBmp.bitmapData);
 showBmp1.x = 0;
 showBmp1.y = 0;
 addChild(showBmp1);
 //
 showBmp2 = new Bitmap(ldrBmp.bitmapData);
 showBmp2.scaleX = 0.3;
 showBmp2.scaleY = 0.3;
 showBmp2.x = 370;
 showBmp2.y = 255;
 addChild(showBmp2);
}


加上預載進度百分比



import flash.display.Loader;
import flash.net.URLRequest;
import flash.events.Event;
import flash.display.Bitmap;
import flash.events.ProgressEvent;
import flash.text.TextField;
import flash.text.TextFormat;

//
var format:TextFormat = new TextFormat();
format.size = 88;
format.color = 0xffff00;
//
var tF:TextField = new TextField();
tF.x = 220;
tF.y = 150;
tF.autoSize = TextFieldAutoSize.LEFT;
tF.defaultTextFormat = format;
addChild(tF);

//
const bmpURL:String = "991210_1.jpg";
//
var ldr:Loader = new Loader();
ldr.load(new URLRequest(bmpURL));
//
ldr.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, onLoaderProgress);
//
ldr.contentLoaderInfo.addEventListener(Event.COMPLETE, bmpWork);

//
function onLoaderProgress(e:ProgressEvent):void{
 tF.text = String(Math.floor(e.bytesLoaded/e.bytesTotal*100));
}

//
var showBmp1:Bitmap;
var showBmp2:Bitmap;
//
function bmpWork(e:Event):void{
 //
 var ldrBmp:Bitmap = ldr.content as Bitmap;
 //
 showBmp1 = new Bitmap(ldrBmp.bitmapData);
 showBmp1.x = 0;
 showBmp1.y = 0;
 addChild(showBmp1);
 //
 showBmp2 = new Bitmap(ldrBmp.bitmapData);
 showBmp2.scaleX = 0.3;
 showBmp2.scaleY = 0.3;
 showBmp2.x = 370;
 showBmp2.y = 255;
 addChild(showBmp2);
}


適用於 Adobe Flash Professional CS5 的 ActionScript 3.0 參考__●flash.display.Loader.content屬性
適用於 Adobe Flash Professional CS5 的 ActionScript 3.0 參考__●flash.display.Bitmap類別
適用於 Adobe Flash Professional CS5 的 ActionScript 3.0 參考__●flash.events.ProgressEvent.PROGRESS

[AS3] 在主時間軸上顯示以BitmapData為基底類別的內嵌資源類別的實體

991209_BitmapData_1.swf



●內嵌資源類別不需撰寫類別檔,僅需在元件庫中作一些指定,就可被關鍵影格上的AS碼操作。
●右鍵單擊元件庫裡的photo_1.jpg,點選 [屬性],在 [點陣圖屬性] 面板做以下設定



//
import flash.display.Bitmap;
import flash.display.Sprite;
//
var container:Sprite = new Sprite()
addChild(container);
//
var bitmap:Bitmap = new Bitmap(new NewPhoto(600,426));
container.addChild(bitmap);
//
addChild(txt1);
addChild(txt2);

2010年12月8日 星期三

[AS3] DisplayObjectContainer.addChild()方法、removeChild()方法

addChild(child:DisplayObject):DisplayObject
將 DisplayObject 子實體加入至此 DisplayObjectContainer 實體。
removeChild(child:DisplayObject):DisplayObject
將指定的 child DisplayObject 實體從 DisplayObjectContainer 實體的子清單中移除。


Sprite類別實體aaa使用graphics屬性繪製了三角形,並加入顯示清單而為Sprite類別實體container的子物件。以 Switch_btn 切換呼叫 addChild() 和 removeChid(),將aaa 加入和移除。



991208_DisplayObjectContainer.addChild、removeChild_2.fla


import flash.display.Sprite;
//
var container:Sprite = new Sprite();
addChild(container);
//
var flag:Boolean = true;
var aaa:Sprite = new Sprite();
aaa.graphics.lineStyle(10, 0xFF2255, 1, false, LineScaleMode.VERTICAL, CapsStyle.NONE, JointStyle.MITER, 10);
aaa.graphics.beginFill(0xffaa00);
aaa.graphics.moveTo(50, 50);
aaa.graphics.lineTo(520, 160);
aaa.graphics.lineTo(320, 300);
aaa.graphics.lineTo(50, 50);
aaa.graphics.endFill();
container.addChild(aaa);
//
switch_btn.buttonMode = true;
switch_btn.addEventListener(MouseEvent.CLICK, removeSprite);
function removeSprite(e:MouseEvent):void{
 if (flag){
  container.removeChild(aaa);
  flag = false;
 }else{
  container.addChild(aaa);
  flag = true;
 }
 //remove_btn.removeEventListener(MouseEvent.CLICK, removeSprite);
}




試著將切換用的按鈕switch_btn當作內嵌資源類別來使用,從舞台上刪除,並從元件庫來做設定,為SwitchBtn類別
switch_btn的label文字也配合切換,以TextField類別實體來做動態處理



991208_DisplayObjectContainer.addChild、removeChild_3.fla


import flash.display.Sprite;
import flash.text.TextField;
import flash.display.MovieClip;
import flash.text.TextFormat;

//建構TextFormat類別實體指定給myTextFormat,設定myTextFormat的屬性值
var myTextFormat:TextFormat = new TextFormat();
with(myTextFormat){
 color = 0x000066;
 size = 16;
 font = "Lucida Fax";
 bold = true;
}

//建構TextField類別實體指定給labelTf
var labelTf:TextField = new TextField();
//設定labelTf的各屬性值
with(labelTf){
 x = -50;
 y = -10;
 width = 100;
 autoSize = TextFieldAutoSize.CENTER;
 //multiline = true;
 //wordWrap = true;
 defaultTextFormat = myTextFormat;
 text = "removeChild";
}

//建構Sprite類別實體指定給container,做為aaa的容器物件,附加到主時間軸上
var container:Sprite = new Sprite();
addChild(container);

//建構内建資源類別SwitchBtn類別的實體,並指定給MovieClip資料型別的Switch_btn
//内建資源類別SwitchBtn類別的基底類別為MovieClip類別
var switch_btn:MovieClip = new SwitchBtn();
addChild(switch_btn);
switch_btn.x = 129;
switch_btn.y = 296;
//開啟switch_btn的buttonMode屬性,使有按鈕滑入滑出按壓互動與出現掌形指標
switch_btn.buttonMode = true;
//mouseChildren - 判斷物件的子系是否支援啟用滑鼠或使用者輸入裝置。
//如果啟用某個物件,則使用者可以使用滑鼠或使用者輸入裝置,與其進行互動。
//預設值為 true。
switch_btn.mouseChildren = false;
//將labelTf加入switch_btn為子實體
switch_btn.addChild(labelTf);

//建構Sprite類別實體指定給aaa;指定aaa各屬性值
var aaa:Sprite = new Sprite();
with(aaa.graphics){
 //graphics類別繪圖
 lineStyle(10, 0xFF22ff, 1, false, LineScaleMode.VERTICAL, CapsStyle.NONE, JointStyle.MITER, 10);
 beginFill(0xffff55);
 moveTo(50, 50);
 lineTo(520, 160);
 lineTo(320, 300);
 lineTo(50, 50);
 endFill();
}
//將aaa加入container為子實體
container.addChild(aaa);

//宣告flag布林變數,初始值為true,做為switch_btn切換作用之判斷
var flag:Boolean = true;
//switch_btn廣播MouseEvent.CLICK事件給removeSprite偵聽
switch_btn.addEventListener(MouseEvent.CLICK, removeSprite);
//
function removeSprite(e:MouseEvent):void{
 if (flag){
  container.removeChild(aaa);
  flag = false;
  labelTf.text = "addChild";
 }else{
  container.addChild(aaa);
  flag = true;
  labelTf.text = "removeChild";
 }
 //remove_btn.removeEventListener(MouseEvent.CLICK, removeSprite);
}


適用於 Adobe Flash Professional CS5 的 ActionScript 3.0 參考__●flash.display.DisplayObjectContainer
適用於 Adobe  Flash  Professional CS5 的 ActionScript  3.0 參考__●flash.display.Graphics
適用於 Adobe Flash Professional CS5 的 ActionScript 3.0 參考__●flash.display.Graphics__lineStyle()方法

2010年12月4日 星期六

[AS3] 不需匯入的類別

在時間軸上撰寫 ActionScript → 不需 import 匯入所有最上層類別、flash.* 套件所包含的類別。
在 *.AS 檔案中撰寫 ActionScript → 不需 import 匯入所有最上層類別

最上層類別 → ArgumentError, arguments, Array, Boolean, Class, Date, DefinitionError, Error, EvalError, Function, Math, Namespace, Number, Object, QName, RangeError, ReferenceError, RegExp,  SecurityError, String, SyntaxError, TypeError, uint, URIError, Vector, VerifyError, XML, XMLList


flash.*套件 → flash.accessibility, flash.data, flash.desktop, flash.display, flash.errors, flash.events, flash.external, flash.filesystem, flash.filters, flash.geom, flash.globalization, flash.html, flash.media, flash.net, flash.net.dns, flash.net.drm, flash.printing, flash.profiler, flash.sampler, flash.security, flash.sensors, flash.system, flash.text, flash.text.engine, flash.text.ime, flash.ui, flash.utils, flash.xml



2010年12月1日 星期三

[AS3] 指定類別檔路徑 - 以下載及設置Tweener類別庫為例

以下載及設置Tweener類別庫為例:

●Tweener Project 的 URL:
http://code.google.com/p/tweener/



●tweener_1_33_74_as3.zip 下載Link
http://code.google.com/p/tweener/downloads/detail?name=tweener_1_33_74_as3.zip



下載 tweener_1_33_74_as3.zip 回來後解壓縮出來為一個 caurina目錄,Tweener的類別檔都在裡面。


使用類別庫之前,打開Flash軟體,做一些設定

  1. 在電腦檔案系統任一處開一個目錄,命名為Classes (或其它名稱),將下載回來解壓縮得到的caurina資料夾整個擲入 Classes目錄。
  2. 以Flash CS3為例,叫出編輯功能表 / 偏好設定 (或CTRL+U),點選左側ActionScript選項,在右側[語言]選項,點選 [ActionScript 3.0設定]按鈕。


  3. 跳出[ActionScript 3.0設定]面板,點擊下圖標示的[瀏覽到路徑]按鈕,指向Classes目錄,陸續按下確定鈕,就設定好類別檔路徑。每當於ActionScript中import某些Classes目錄中的類別時,Flash將會前往此指定路徑搜尋類別檔。