// 4프레임 코드같은 동작을하는 ActionScript 3.0소스입니다.
if (_framesloaded == _totalframes) {
gotoAndPlay(6)
}
// 5프레임 코드
gotoAndPlay(4);
// 4프레임 코드‘_’를 없애고 각 단어의 첫 글자를 대문자로 바꾼 ActionScript 3.0의 “framesLoaded”와 “framesLoaded” 는 확실히 ActionScript 1.0에서의 그것보다 명료해서 배우기도 쉽습니다.
if (framesLoaded == totalFrames) {
gotoAndPlay(6);
}
// 5프레임 코드
gotoAndPlay(4);
// 1프레임 코드아래는 ActionScript 3.0코드입니다
setInterval(moveBall, 20);
function moveBall () {
ball._x += 10;
}
// 1프레임 코드마찬가지로 차이점은 ActionScript 1.0의 “_x”에서 언더바를 제거하여 ActionScript 3.0에서는 “x”를 사용한다는 것입니다. ActionScript 3.0에서도 무비클립 인스턴스는 여전히 각각의 인스턴스 이름을 통해 화면에서 움직이게 할 수 있습니다. 여전히 ActionScript 3.0에서 setInterval()함수도 동일하게 쓸 수 있습니다. 하지만 새로 추가된 Timer 클래스를 쓰면 더욱 향상된 재생, 정지 또는 반복기능을 사용할 수 있습니다.
setInterval(moveBall, 20);
function moveBall () {
ball.x += 10;
}
var rpm = 30;아래는 ActionScript 3.0 코드입니다.
var radius = 150;
var centerX = 230;
var centerY = 200;
var theta = 0;
var degreesPerSecond = rpm * 360 / 60;
var now = getTimer();
var intervalID = setInterval(moveClipAroundCircle, 20, ball);
function moveClipAroundCircle (theClip) {
var then = now;
now = getTimer();
var elapsed = now - then;
var numSeconds = elapsed / 1000;
var degreeIncrement = degreesPerSecond * numSeconds;
theta += degreeIncrement;
theta %= 360;
var radians = degreesToRadians(theta);
theClip._x = centerX + Math.cos(radians) * radius;
theClip._y = centerY - Math.sin(radians) * radius;
}
function degreesToRadians(degrees) {
return (degrees/180) * Math.PI;
}
// Code on frame 1역시 변수명에서 언더바가 빠진 게 두 코드의 차이입니다. 때문에 ActionScript 3.0 코드가 ActionScript 1.0 코드보다 깔끔합니다. 안 어렵습니다.
var rpm = 30;
var radius = 150;
var centerX = 230;
var centerY = 200;
var theta = 0;
var degreesPerSecond = rpm * 360 / 60;
var now = getTimer();
var intervalID = setInterval(moveClipAroundCircle, 20, ball);
function moveClipAroundCircle (theClip) {
var then = now;
now = getTimer();
var elapsed = now - then;
var numSeconds = elapsed / 1000;
var degreeIncrement = degreesPerSecond * numSeconds;
theta += degreeIncrement;
theta %= 360;
var radians = degreesToRadians(theta);
theClip.x = centerX + Math.cos(radians) * radius;
theClip.y = centerY - Math.sin(radians) * radius;
}
function degreesToRadians(degrees) {
return (degrees/180) * Math.PI;
}