[Flash] /attach/1/1183970936.swf


使用說明:錄影鍵的紅燈有亮代表錄影中。
ActionScript:
recMode = 0;
recStart = 0;
playBack = 0;
playRewind = 0;
//圓
r=10;
var mc1 = this.createEmptyMovieClip("ball"、1);
mc1.lineStyle(2,0x000000,100);
mc1.beginFill(0xFFCC00);
mc1.moveTo(r、0);
for (var i = 0; i <= 360; i++) {
mc1.lineTo(Math.cos(Math.PI/180*i)*r、Math.sin(Math.PI/180*i)*r);
}
mc1.endFill();
mc1._x = 225;
mc1._y = 150;

ball.onPress = function(){
this.startDrag();
}
ball.onRelease = function(){
this.stopDrag();
}
ball.onReleaseOutside = function(){
this.stopDrag();
}

ball.onLoad = function() {
friction = 0.9;
ball_x = 0;
ball_y = 0;
the_x = this._x;
the_y = this._y;
}
ball.onEnterFrame = function() {
pre_x = the_x;
the_x = this._x;
pre_y = the_y;
the_y = this._y;
ball_x = (the_x - pre_x)*friction;
ball_y = (the_y - pre_y)*friction;
if ((this._x + ball_x) >=(300-(this._width/2)) or (this._x + ball_x) <=(0+(this._width/2))) {
this._x -= ball_x;
} else {
this._x += ball_x;
}
if ((this._y + ball_y) >=(300-(this._width/2)) or (this._y + ball_y) <=(0+(this._width/2))) {
this._y -= ball_y;
} else {
this._y += ball_y;
}
}
// 錄影.播放.倒帶
var mc2 = this.createEmptyMovieClip("ball_rec"、2);
ball_rec.onLoad = function() {
rec = 0;
}
ball_rec.onEnterFrame = function() {
if (recMode == 1) {
if (recStart == 1) {
rec_x = new Array();
rec_y = new Array();
rec = 0;
recStart = 0;
rec_len = 0;
}
rec++;
rec_x[rec] = ball._x;
rec_y[rec] = ball._y;
rec_len = rec_x.length;
} else if (playBack == 1) {
if (startPlay == 1) {
main_rec = rec_len;
rec = 0;
startPlay = 0;
}
if (rec < main_rec) {
rec++;

ball._x = rec_x[rec];
ball._y = rec_y[rec];
} else {
playBack = 0;
ball.ball_x = 0;
ball.ball_y = 0;
}
} else if (playRewind == 1) {
if (startPlay == 1) {
rec = rec_len;
startPlay = 0;
}
if (rec > 0) {
rec--;
ball._x = rec_x[rec];
ball._y = rec_y[rec];
} else {
rec = 0;
playRewind = 0;
ball.ball_x = 0;
ball.ball_y = 0;
}
}
updateAfterEvent();
}
// 三個按鈕
var mc3 = this.createEmptyMovieClip("button1"、3);
mc3.lineStyle(2,0x000000,100);
mc3.beginFill(0xcccccc);
mc3.moveTo(300、270);
mc3.lineTo(300、290);
mc3.lineTo(340、290);
mc3.lineTo(340、270);
mc3.lineTo(300、270);
mc3.endFill();

var mc4 = this.createEmptyMovieClip("button2"、4);
mc4.lineStyle(2,0x000000,100);
mc4.beginFill(0xcccccc);
mc4.moveTo(350、270);
mc4.lineTo(350、290);
mc4.lineTo(390、290);
mc4.lineTo(390、270);
mc4.lineTo(350、270);
mc4.endFill();

var mc5 = this.createEmptyMovieClip("button3"、5);
mc5.lineStyle(2,0x000000,100);
mc5.beginFill(0xcccccc);
mc5.moveTo(400、270);
mc5.lineTo(400、290);
mc5.lineTo(440、290);
mc5.lineTo(440、270);
mc5.lineTo(400、270);
mc5.endFill();

var mc6 = this.createEmptyMovieClip("b1"、6);
mc6.beginFill(0x555555);
mc6.moveTo(315、280);
mc6.lineTo(325、285);
mc6.lineTo(325、275);
mc6.lineTo(315、280);
mc6.endFill();

r1=5;
var mc7 = this.createEmptyMovieClip("b2"、7);
mc7.beginFill(0xaa0000);
mc7.moveTo(r1、0);
for (var i = 0; i <= 360; i++) {
mc7.lineTo(Math.cos(Math.PI/180*i)*r1、Math.sin(Math.PI/180*i)*r1);
}
mc7.endFill();
mc7._x = 370;
mc7._y = 280;

var mc8 = this.createEmptyMovieClip("b3"、8);
mc8.beginFill(0x555555);
mc8.moveTo(415、275);
mc8.lineTo(415、285);
mc8.lineTo(425、280);
mc8.lineTo(415、275);
mc8.endFill();

button1.onRelease = function(){
mc7.beginFill(0xaa0000,100);
mc7.moveTo(r1、0);
for (var i = 0; i <= 360; i++) {
mc7.lineTo(Math.cos(Math.PI/180*i)*r1、Math.sin(Math.PI/180*i)*r1);
}
mc7.endFill();
playBack = 0;
playRewind = 1;
startPlay = 1;
recMode = 0;
}
button2.onRelease = function(){
if (recMode == 0){
mc7.beginFill(0xff0000);
mc7.moveTo(r1、0);
for (var i = 0; i <= 360; i++) {
mc7.lineTo(Math.cos(Math.PI/180*i)*r1、Math.sin(Math.PI/180*i)*r1);
}
mc7.endFill();

recMode = 1;
recStart = 1;
} else {
mc7.beginFill(0xaa0000);
mc7.moveTo(r1、0);
for (var i = 0; i <= 360; i++) {
mc7.lineTo(Math.cos(Math.PI/180*i)*r1、Math.sin(Math.PI/180*i)*r1);
}
mc7.endFill();
recMode = 0;
}
}
button3.onRelease = function(){
mc7.beginFill(0xaa0000,100);
mc7.moveTo(r1、0);
for (var i = 0; i <= 360; i++) {
mc7.lineTo(Math.cos(Math.PI/180*i)*r1、Math.sin(Math.PI/180*i)*r1);
}
mc7.endFill();
playBack = 1;
playRewind = 0;
startPlay = 1;
recMode = 0;
}

錄影原理是利用陣列記錄物件走過的座標。

2005/10/25 - 修正:停止鍵似乎沒必要,移除了。
2005/10/26 - 修正:加入倒帶鍵(Rewind)。
2005/10/26 00:22 2005/10/26 00:22
2005/10/26 00:22 

[Flash] /attach/1/1097917606.swf


ActionScript:
//文字格式
var txtformat = new TextFormat();
txtformat.font = "Arial";
txtformat.size = 15;
txtformat.bold = true;
//文字初始化
createTextField("txt"、1、150、140、140、20);
txt.text = "The Flash FPS :"
txt.setTextFormat(0、txt.length、txtformat);

FPS();

function FPS(){
var _fps = 0;
this.onEnterFrame = function() {
_fps++;
};
setInterval(function (){
//文字
txt.text = "The Flash FPS : "+_fps;
txt.setTextFormat(0、txt.length、txtformat);
_fps = 0;
}、1000);
}
Flash 的 FPS(Frames Per Second)會因每部電腦效能不同而有差異,順便練習文字格式語法。
拖曳捲軸時可發現 Flash FPS 嚴重降低..
2005/10/25 04:51 2005/10/25 04:51
2005/10/25 04:51 

[Flash] /attach/1/1368739144.swf


ActionScript:
// 繪圖板
var mc = this.createEmptyMovieClip("drawing_board"、1);
drawing_board.onMouseDown = function() {
this.moveTo(this._xmouse、this._ymouse);
this.onMouseMove = function() {
drawing_board.lineStyle(2,0x000000,100);
newX = this._xmouse;
newY = this._ymouse;
this.lineTo(newX、newY);
};
};
drawing_board.onMouseUp = function() {
this.onMouseMove = null;
};
// 清除按鈕
var mc2 = this.createEmptyMovieClip("button1"、2);
mc2.lineStyle(2,0x000000,100);
mc2.beginFill(0xcccccc);
mc2.moveTo(400、270);
mc2.lineTo(400、290);
mc2.lineTo(440、290);
mc2.lineTo(440、270);
mc2.lineTo(400、270);
mc2.endFill();
button1.onRelease = function(){
drawing_board.clear();
}
右下角的小按鈕就佔了一半語法了..
2005/10/19 04:22 2005/10/19 04:22
2005/10/19 04:22 

[Flash] /attach/1/1286196627.swf


ActionScript:
// 設文字框 border 和文字 myText 目的在讓兩者之間可設定邊界
createTextField("border"、1、20、20、410、260);
border.background = true;
border.backgroundColor = 0xEEFFEE;
createTextField("myText"、2、30、30、390、240);
myText.wordWrap = true;
myText.multiline = true;

//有這三行版面才會採 HTML 方式編排
XMLStyle = new TextField.StyleSheet();
//XMLStyle.load(); //這裡可以載入CSS
myText.styleSheet = XMLStyle;

//載入 XML
myXML = new XML();
myXML.ignoreWhite = true;
myXML.load("index.xml");
myXML.onLoad = function(success){
if(success){
myText.text = showXML(myXML);
}
}

// 在 XML 中挑出資料
function showXML(_XML){
var myText = "<b>‧Raie's Blog XML 標題讀取示範‧</b><br/><br/>";
for (var i = 0; i<_XML.firstChild.firstChild.childNodes.length; i++) {
if(_XML.firstChild.firstChild.childNodes[i].nodeName == "item"){
for (var j = 0; j<_XML.firstChild.firstChild.firstChild.nextSibling.nextSibling.nextSibling.nextSibling.nextSibling.childNodes.length; j++){
if(_XML.firstChild.firstChild.childNodes[i].childNodes[j].nodeName == "title"){
myText = myText + _XML.firstChild.firstChild.childNodes[i].childNodes[j].firstChild.nodeValue + "<br/>";
}
}
}
}
return myText;
}
這次實驗發現,XML檔必須和Flash檔放在一起才讀得到,不知道是否因為 Flash8 安全性問題。
此語法僅適用於 TattorTools 的 XML 檔案,將 index.xml 改成 http://blog.raienet.com/index.xml 在 Flash 中按 Ctrl + Enter 仍然可以預覽。

用 Raie's Blog XML 不是個好例子.. 挑出資料的過程太複雜了。只不過它是我想嚐試作法之一。另外這個例子也有一個方便,如果要對照 XML 檔案,只要按 blog 右上角的橘色按鈕就可以了。
2005/10/09 20:30 2005/10/09 20:30
2005/10/09 20:30 

[Flash] /attach/1/1144248830.swf


ActionScript:
//拖曳粉紅色方塊碰觸黃色方塊
var mc1 = this.createEmptyMovieClip("square1"、1);
mc1.lineStyle(2,0x000000,100);
mc1.beginFill(0xFFCC00);
mc1.moveTo(0、0);
mc1.lineTo(0、100);
mc1.lineTo(100、100);
mc1.lineTo(100、0);
mc1.lineTo(0、0);
mc1.endFill();
setProperty("square1",_x,60);
setProperty("square1",_y,60);

var mc2 = this.createEmptyMovieClip("square2"、2);
mc2.lineStyle(2,0x000000,100);
mc2.beginFill(0xFFDDDD);
mc2.moveTo(-20、-20);
mc2.lineTo(-20、20);
mc2.lineTo(20、20);
mc2.lineTo(20、-20);
mc2.lineTo(-20、-20);
mc2.endFill();
setProperty("square2"、_x、400);
setProperty("square2"、_y、250);

square2.onPress = function(){
this.startDrag();
}
square2.onRelease = function(){
this.stopDrag();
}
square2.onReleaseOutside = function(){
this.stopDrag();
}

var x1 = 0; //0:未碰觸、1:左方碰觸、2:右方碰觸 3:上方碰觸、4:下方碰觸

_root.onEnterFrame = function () {
if (square2.hitTest(square1)) {
//在 square1 外面
if (square2._x <= 60){
x1 = 1;
setProperty("square2"、_x、40);
} else if (square2._x > 160) {
x1 = 2;
setProperty("square2"、_x、180);
}
if (square2._y <= 60){
x1 = 3;
setProperty("square2"、_y、40);
} else if (square2._y > 160) {
x1 = 4;
setProperty("square2"、_y、180);
}
//在 square1 裡面
if (square2._x > 60 && square2._x <= 160 && square2._y > 60 && square2._y <= 160){
//正常狀況的處理
if (x1 == 1){
setProperty("square2"、_x、40);
} else if (x1 == 2){
setProperty("square2"、_x、180);
} else if (x1 == 3){
setProperty("square2"、_y、40);
} else if (x1 == 4){
setProperty("square2"、_y、180);
}
//異常狀況的處理
if(x1 == 0){
if (square2._x <= 110){
setProperty("square2"、_x、40);
} else if (square2._x > 110){
setProperty("square2"、_x、180);
}
}
}
setProperty("square1"、_alpha、50);
} else {
x1 = 0;
setProperty("square1"、_alpha、100);
}
}
比想像中還要複雜一點...
2005/10/01 04:08 2005/10/01 04:08
2005/10/01 04:08 

[Flash] /attach/1/1095436982.swf


2005/10/1 - ActionScript:
createCircle(225,150,40); //x1:x座標, y1:y座標, r1:半徑

function createCircle(x1,y1,r){
var mc = this.createEmptyMovieClip("circle1", 1);
mc.lineStyle(2,0x000000,100);
mc.beginFill(0xFFCC00);
mc.moveTo(r, 0);
for (var i = 0; i <= 360; i++) {
mc.lineTo(Math.cos(Math.PI/180*i)*r, Math.sin(Math.PI/180*i)*r);
}
mc.endFill();
mc._x = x1;
mc._y = y1;
}
另一種更簡潔的 lineTo 作法

2005/9/22 - ActionScript:
createCircle(225,150,40); //x1:x座標, y1:y座標, r1:半徑

function createCircle(x1,y1,r1){
var mc = this.createEmptyMovieClip("circle1", 1);
mc.lineStyle(2,0x000000,100);
mc.beginFill(0xFFCC00);
mc.moveTo(x1+r1, y1);
mc.curveTo(x1+r1, y1+Math.tan(Math.PI/8)*r1, x1+Math.sin(Math.PI/4)*r1, y1+Math.sin(Math.PI/4)*r1);
mc.curveTo(x1+Math.tan(Math.PI/8)*r1, y1+r1, x1, y1+r1);
mc.curveTo(x1-Math.tan(Math.PI/8)*r1, y1+r1, x1-Math.sin(Math.PI/4)*r1, y1+Math.sin(Math.PI/4)*r1);
mc.curveTo(x1-r1, y1+Math.tan(Math.PI/8)*r1, x1-r1, y1);
mc.curveTo(x1-r1, y1-Math.tan(Math.PI/8)*r1, x1-Math.sin(Math.PI/4)*r1, y1-Math.sin(Math.PI/4)*r1);
mc.curveTo(x1-Math.tan(Math.PI/8)*r1, y1-r1, x1, y1-r1);
mc.curveTo(x1+Math.tan(Math.PI/8)*r1, y1-r1, x1+Math.sin(Math.PI/4)*r1, y1-Math.sin(Math.PI/4)*r1);
mc.curveTo(x1+r1, y1-Math.tan(Math.PI/8)*r1, x1+r1, y1);
}
curveTo 的作法,這個能看得懂的就厲害了...
2005/10/01 03:26 2005/10/01 03:26
2005/10/01 03:26 

[Flash] /attach/1/1025040576.swf


ActionScript:
//拖曳粉紅色方塊碰觸黃色方塊
var mc1 = this.createEmptyMovieClip("square1", 1);
mc1.lineStyle(2,0x000000,100);
mc1.beginFill(0xFFCC00);
mc1.moveTo(0, 0);
mc1.lineTo(0, 100);
mc1.lineTo(100, 100);
mc1.lineTo(100, 0);
mc1.lineTo(0, 0);
mc1.endFill();
setProperty("square1", _x, 60);
setProperty("square1", _y, 60);

var mc2 = this.createEmptyMovieClip("square2", 2);
mc2.lineStyle(2,0x000000,100);
mc2.beginFill(0xFFDDDD);
mc2.moveTo(0, 0);
mc2.lineTo(0, 40);
mc2.lineTo(40, 40);
mc2.lineTo(40, 0);
mc2.lineTo(0, 0);
mc2.endFill();
setProperty("square2", _x, 400);
setProperty("square2", _y, 250);

square2.onPress = function(){
this.startDrag();
}
square2.onRelease = function(){
this.stopDrag();
}

_root.onEnterFrame = function () {
if (square2.hitTest(square1)) {
setProperty("square1", _alpha, 50);
} else {
setProperty("square1", _alpha, 100);
}
}
2005/09/30 17:44 2005/09/30 17:44
2005/09/30 17:44 

我們知道 function 有這兩種寫法:

1.
function test(){
trace("TEST");
}

2.
test = function(){
trace("TEST");
}

使用第 2 種方式將 function 指定給變數 test 時,在未指定前呼叫此 function 將不會得到任何結果,第 1 種方式則不受此限制。

錯誤用法:
test();

test = function(){
trace("TEST"); //
}

正確用法:
test = function(){
trace("TEST"); //TEST
}

test();
2005/09/28 14:40 2005/09/28 14:40
2005/09/28 14:40 

ActionScript:
i = 0;

this.onEnterFrame = function(){
trace(i);
i++;
if (i > 50){
this.onEnterFrame = null;
}
};
2005/09/25 01:12 2005/09/25 01:12
2005/09/25 01:12 

[Flash] /attach/1/1213262273.swf


ActionScript:
var x1 = 225; //圓心x座標
var y1 = 150; //圓心y座標
var r1 = 120; //半徑
var n = 1; //角度

_root.onEnterFrame = function (){
var mc = this.createEmptyMovieClip("line2", n);
mc.lineStyle(2,0x000000,100);
a = r1*Math.cos(n*Math.PI/180);
b = r1*Math.sin(n*Math.PI/180);
c = r1*Math.cos((n+1)*Math.PI/180);
d = r1*Math.sin((n+1)*Math.PI/180);
with (line2) {
mc.moveTo(x1+a, y1+b);
mc.lineTo(x1+c, y1+d);
}
if (n<=360){
n = n+1;
}
}
2005/09/23 08:55 2005/09/23 08:55
2005/09/23 08:55