Monthly Archive for August, 2006

Page 2 of 3

Easing motion in Frame

프레임 모션에 easing 값을 넣어서 적용하는 방법…
프레임의 길이가 적어도 200 frame 이상이 되여야만 어느정도 부드러운 효과를 기대할수 있다.
일반적인 트윈같은 경우 action 으로 하는 경우가 훨씬 자연스럽지만 프레임 모션을 사용해야할경우
이 방법을 사용하면 action 같은 frame 모션이 가능하다.

import mx.transitions.Tween;
import mx.transitions.easing.*;
 
mc._frame = mc._currentframe;
 
var myTween:Tween = new Tween(mc, "_frame", Strong.easeOut, mc._currentframe, 300, 1, true);
 
myTween.onMotionChanged = function() {
mc.gotoAndStop(Math.round(mc._frame));
};
myTween.onMotionFinished = function() {
this.yoyo();
};

프레임 속성을 동적으로 할당해서 Tween class 를 사용하여 easing function 를 적용하여 구현.

The delete Keyword

The delete keyword in Flash is used to remove variable definitions. It doesn’t delete objects from memory (this happens behind the scenes using something called the “Garbage Collector”), it just takes a variable you’ve created and gets rid of it so that it is no longer accessible and is no longer present through iteration (for..in loops, etc.).

Internally, the Garbage Collector, or GC for short, knows when to physicially delete objects in memory when they no longer have any variables that reference them. So, for example, if you have two variables A and B and they both reference ObjectX, deleting variable A will not cause ObjectX to be removed from memory by the GC because variable B still references it. However, if you delete both variables A and B, there will be no more references to ObjectX and the GC will recognize that it needs to be removed from memory

ActionScript Code:

var a:Object = new Object();

var b:Object = a; // reference same new Object();

delete a;

trace(b); // [object Object] – still exists in memory

delete b; // GC will mark object for deletion from memory

This works practically the same way for Flash 8 and Flash 9 (ActionScript 1, 2, and 3), though some changes were made in 8 to improve the GC. (Note: GC deletion from memory is not immediate.)

Though the GC has not really changed much with ActionScript 3 and the new virtual machine that runs it, what has changed is the behavior of the delete keyword. Now, the delete keyword only works for dynamic properties of a class instance and not declared class memebers (variables or methods). With ActionScript 1 and 2, delete could be used for anything. ActionScript 3 only lets you delete dynamic variables and locks those which are not.

// ActionScript 2

class DeleteVarClass {

public var myVar:Number;

function DeleteVarClass() {

myVar = 1;

trace(myVar); // 1

delete myVar;

trace(myVar); // undefined

}

}

// ActionScript 3

package {

public class DeleteVarClass {

public var myVar:Number;

public function DeleteVarClass() {

myVar = 1;

trace(myVar); // 1

delete myVar;

trace(myVar); // 1

}

}

}

Because myVar in the above example was declared as part of the class definition, it cannot be deleted using delete in ActionScript 3.

Since you cannot delete class members in ActionScript 3, if you want to cause a variable to no longer reference an object or value in memory you should set your variable’s value to null instead of deleting it.

Garbage Collectors는 참조값이 없는한 사용되지 않는 변수에 대한 메모리를 자동으로 찾아서 소거해주는 메모리 소거 프로세스이다. 기능상으로는 AS2.0 이나 AS3.0 이나 크게  달라진 부분은 없지만 한가지, AS3.0 에서는 클래스 맴버변수로 선언된 변수는 제거할수 없게 바뀌었다.

ZenDoc 1.0 Released

ZenDoc 1.0 has been released.

ZenDoc is a free, open source ActionScript documentation utility for converting AS 2 class files commented with JavaDoc style comments into HTML documentation.

JavaDoc 형식으로 작성한 AS2.0 파일을 Html 형식의 문서로 전환해 준다.

로컬에서 작동하는 Application이 아니라 웹서버(PHP)에서 실행되는 형식이다.

개인적으로 작성한 클래스 파일을 이런형식으로 만들어 보는건 큰 의미는 없겠지만 제작한 클래스를 배포하거나 공동작업에 필요한 클래스를 공유할때 다른사용자에게 유용할듯 싶다.

주석을 JavaDoc형식으로 작성하긴 하지만 빠쁠땐 그냥 넘어가는 경우도 있는데 나중을 위해 좀더 부지런해져야 할 것같다.

Changing the frame rate in movie

Using ActionScript 3, you can dynamically change the frame rate of your movie using the Stage class.

The Stage class (flash.display.Stage) is the class assigned to the stage object which is accessible from your main movie sprite/movie clip (or others within the same security sandbox) using the stage property. The stage object has a frameRate property which can contain any value between 0.01 and 1000 and determines the frame rate at which the Flash player plays back your movie. Changing this value lets you change the frame rate at runtime.

// change frame rate to 12 fps:

stage.frameRate = 12;

이전 버전에서는 한번 정한 framerate 는 바뀔수가 없었다. 즉 동적으로 frame 속도를 조절할수 없었음.

근데 과연 frameRate 가 1000까지 지원할까?…. 지원하더라도 눈으로 확인은 불가능 할듯.

다만 각각의 swf 파일의 속도는 조절안되고 전체 stage 의 속도만 조절되는것 같다.

Detecting When the Mouse Leaves

One thing about previous versions of ActionScript was that you could never tell when the user no longer had his or her mouse over the Flash movie. This made it hard for people to know whether or not the user is still interacting with their movie or if they’ve given up and moved on to something more interesting. This was especially a problem for custom cursors where, if the user moved the cursor off the Flash movie, the custom cursor would still remain in the Flash movie not moving while the real cursor could be seen moving around every where else. ActionScript 3 now allows you to detect when the mouse has left the flash movie using the stage’s mouseLeave event. This event happens whenever the mouse exits the Flash movie. There is no mouseEnter event, but you can use mouseMove for that since mouseMove only occurs in Flash (for the stage, or really any, object) when the mouse is within the bounds of the movie.

html에서의 플래시 영역 밖으로 마우스 커서를 옮겼을경우 이전에는 정확히 그것을 알아낼 방법이 없었다. 마우스 커서가 안보인다 하더라도 엄연히 플래시 오브젝트 안에 남아서 실행되고 있었는데

이것을 as3.0 에서는 체크할수 있게 되었다.

package {
 
    import flash.display.Sprite;
    import flash.events.Event;
    import flash.events.MouseEvent;
    import flash.ui.Mouse;
 
    public class Test extends Sprite {
 
        private var cursor:Sprite = new Sprite();
 
        public function Test() {
 
            cursor.graphics.beginFill(0xFF);
            cursor.graphics.drawRect(0, 0, 25, 25);
 
            addChild(cursor);
 
            stage.addEventListener(Event.MOUSE_LEAVE, cursorHide);
            stage.addEventListener(MouseEvent.MOUSE_MOVE, cursorFollow);
 
            Mouse.hide();
        }
 
        public function cursorHide(evt:Event):void {
            cursor.visible = false;
        }
 
        public function cursorFollow(evt:MouseEvent):void {
 
            if (!cursor.visible) cursor.visible = true;
            cursor.x = stage.mouseX;
            cursor.y = stage.mouseY;
 
            evt.updateAfterEvent();
        }
    }
}