| <サンプル1> |
<ステージ等の準備>
● 500*200、背景色:0x999999、fsp:60のステージ
● 直径6pxの赤い●を描きシンボルに変換、リンケージ識別子を p とする。
● ステージ右下部に、ReStartボタンを配し、インスタンス名を、btn とする。 |
|
|
| <スクリプト> (as2.0) |
import mx.transitions.Tween;
import mx.transitions.easing.*;
var lineColor = 0xffffff;
linetoPoint();
function linetoPoint() {
btn.enabled = false;
var point = [{x:75, y:55}, {x:140, y:155}, {x:215, y:115}, {x:335, y:160},
{x:435, y:100}, {x:275, y:45}];
var pointNum = point.length;
mc1 = this.createEmptyMovieClip("mc1", 1);
mc2 = this.attachMovie("p", "p", 2);
mc1.lineStyle(2,lineColor,100);
mc1.moveTo(point[0].x,point[0].y);
var n = 1;
lineDraw(n);
function lineDraw(n) {
if (n == pointNum) {
m = 0;
} else {
m = n;
}
tweenx = new Tween(mc2, "_x", None.easeIn, point[n - 1].x, point[m].x, 30);
tweeny = new Tween(mc2, "_y", None.easeIn, point[n - 1].y, point[m].y, 30);
tweeny.onMotionChanged = function() {
mc1.lineTo(mc2._x,mc2._y);
};
tweeny.onMotionFinished = function() {
n++;
if (n == pointNum + 1) {
mc2._visible = false;
btn.enabled = true;
} else {
lineDraw(n);
}
};
}
}
btn.onRelease = function() {
linetoPoint();
}
|
| <サンプル2> |
<ステージ等の準備>
● 300*350、背景色:0x999999、fsp:48のステージ
**以下に配置するものは一つの画面でいろいろ表示したいこの場合に使うもので、単独の表示には必要としない。
●コンポーネントのラジオボタンをステージにD&Dで導入する(groupName:shape、label:polygon, star、data:0, 1 )
●コンポーネントのチェックボックスをステージに導入する(label:colored Fill、インスタンス名:checkBox)
●コンポーネントのコンボボックスをステージに導入する(インスタンス名:comboBox、labels:6,3,4,5,7,8、rowCount:7)
●ステージにボタンを配置する(インスタンス名:start_btn)
|
このページのコンテンツには、Adobe Flash Player の最新バージョンが必要です。

|
import mx.transitions.Tween;
import mx.transitions.easing.*;
var x0 = 150;
var y0 = 150;
var r = 100;
var point = [];
var lineColor = 0xffffff;
start_btn.onRelease = function() {
start_btn.enabled = false;
var num = comboBox.value;
if (shape.getValue() == 0) {
for (i = 0; i < num; i++) {
var rd = 2 * Math.PI / num * i - 1 / 2 * Math.PI;
point[i] = {x:x0 + r * Math.cos(rd), y:y0 + r * Math.sin(rd)};
}
} else {
num = 2*num;
for (i = 0; i < num; i++) {
var rd = 2 * Math.PI / num * i - 1 / 2 * Math.PI;
if(i%2) {
point[i] = {x:x0 + 0.5*r * Math.cos(rd), y:y0 + 0.5*r * Math.sin(rd)};
} else {
point[i] = {x:x0 + r * Math.cos(rd), y:y0 + r * Math.sin(rd)};
}
}
}
drawPolygon(num);
};
function drawPolygon(pointNum) {
mc1 = this.createEmptyMovieClip("mc1", 1);
mc2 = this.createEmptyMovieClip("mc2", 2);
mc1.lineStyle(2,lineColor,100);
if (checkBox.value) {
var color = Math.random() * 255 * 255 * 255;
mc1.beginFill(color);
}
mc1.moveTo(point[0].x,point[0].y);
mc2._x = point[0].x;
mc2._y = point[0].y;
var n = 1;
lineDraw(n);
function lineDraw(n) {
if (n == pointNum) {
m = 0;
} else {
m = n;
}
tween0 = new Tween(mc2, "_x", None.easeOut, pointx[n - 1], pointx[n - 1], 5);
tween0.onMotionFinished = function() {
tweenx = new Tween(mc2, "_x", None.easeOut, point[n - 1].x, point[m].x, 15);
tweeny = new Tween(mc2, "_y", None.easeOut, point[n - 1].y, point[m].y, 15);
tweeny.onMotionChanged = function() {
mc1.lineTo(mc2._x,mc2._y);
};
tweenx.onMotionFinished = function() {
n++;
if (n == pointNum + 1) {
start_btn.enabled = true;
} else {
lineDraw(n);
}
};
};
}
}
|
|