Archive for the 'Flash' Category

Page 2 of 2

Classes in As and Java or C++

[퍼온글] 출처 : <Flex 2 language Reference 36 page>

Programmers familiar with object-oriented programming (OOP) in Java or C++ may think of objects as modules that contain two kinds of members: data stored in member variables or properties, and behavior accessible through methods. The ECMAScript edition 4 draft, the standard upon which ActionScript 3.0 is based, defines objects in a similar but slightly different way. In the ECMAScript draft, objects are simply collections of properties. These properties are containers that can hold not only data, but also functions or other objects. If a function is attached to an object in this way, it is called a method.
While the ECMAScript draft definition may seem a little odd to programmers with a Java or C++ background, in practice, defining object types with ActionScript 3.0 classes is very similar to the way classes are defined in Java or C++. The distinction between the two definitions of object is important when discussing the ActionScript object model and other advanced topics, but in most other situations the term properties means class member variables as opposed to methods. The Flex 2 Language Reference, for example, uses the term properties to mean variables or getter-setter properties. It uses the term methods to mean functions that arepart of a class.

One subtle difference between classes in ActionScript and classes in Java or C++ is that in ActionScript, classes are not just abstract entities. ActionScript classes are represented by class objects that store the class’s properties and methods. This allows for techniques that may seem alien to Java and C++ programmers, such as including statements or executable code at the top level of a class or package.

Another difference between ActionScript classes and Java or C++ classes is that every ActionScript class has something called a prototype object. In previous versions of ActionScript, prototype objects, linked together into prototype chains, served collectively as the foundation of the entire class inheritance hierarchy. In ActionScript 3.0, however, prototype objects play only a small role in the inheritance system. The prototype object can still be useful, however, as an alternative to static properties and methods if you want to share a property and its value among all the instances of a class.

In the past, advanced ActionScript programmers could directly manipulate the prototype chain with special built-in language elements. Now that the language provides a more mature implementation of a class-based programming interface, many of these special language elements, such as __proto__ and __resolve, are no longer part of the language.

Moreover, optimizations of the internal inheritance mechanism that provide significant Flash Player performance improvements preclude direct access to the inheritance mechanism.
actionscript 와 java or c++ 의 class 간의 개념이 약간 다르다.
어찌보면 다아나믹한 움직임을 구현하기 위해선 필요한 차이점인지 모른다.
그래도 ECMAScript 기반의 언어라 그런지 java 와는 외향이 거의 흡사해진다는 느낌이다.

prototype 은 뭔가 꺼림직해서 이전부터 건드리지 않은 부분이지만 아니나 다를까 성능에 문제가 있을 수 있다고 하니 protoype object 는 터치하지 말아야 겠다…

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 에서는 클래스 맴버변수로 선언된 변수는 제거할수 없게 바뀌었다.

Actionscript initialization

flash에서 어느정도 actionscript 를 다룰줄 아는 사람이라면 output 창을 통해 출력되는 에러메시지나 오류를 해석해서 문제를 해결할 수 있다. 하지만 정말정말 코딩 자체에 사소한 실수가 없다는 생각이 들때,…..

왜 생각한대로 작동안하는걸까?…이건 분명 프로그램 버그일거야….

라는 생각이 들때가 있다…..하지만 컴퓨터는 거짓말을 하지 않는다. 분명 어떤 문제로 인해 생각한대로 작동하지 않을뿐이다.
이런 문제의 상당부분은 바로 플래시의 초기화 문제이다.(많은 경우가 이런 상황에 부딪힐수 있다는 의미) 즉 무비클립을 attach 하거나 컴포넌트(component) 를 사용했을경우…..특히 자주 발생하는 듯 싶다.

무비클립의 초기화 과정은 타임라인 이후에 일어난다. 따라서 제아무리 처리속도가 빠르다 하더라도 덩치가 큰 프로그램일경우 초기화하는  과정에 어느정도  딜레이가 발생하게 된다.

특히 웹에서 실행할경우 로딩을 고려하지 않고 제작할 경우 문제가 심각해진다. 또한 클래스로 제작할경우 즉 좀 복잡한 로직에 의해 구현되는 어플리케이션이나 사이트일 경우 연결한 무비클립이나 컴포넌트와 같은 프레임 상에 클래스를 사용하여 코딩을 했을 경우 초기화 타임으로 인한 오류가 발생할수 있다는 것이다.

플래시에서 제공하는 컴포넌트는 특히 덩치가 더 커서 상대적으로 프레임에 나타났을때 인식하는 속도가 느리다.(사람이 체감하지 못하겠지만 컴퓨터처리속도는 아마도…)

따라서 컴포넌트를 사용할경우 그것에 해당하는 클래스의 처리순서를 똑 어느정도 딜레이를 주어 처리한다면 초기화 문제를 해결할수 있을 것이다. 1frame 정도 후에 처리한다면 초기화하고도 충분한(?) 시간…..^^

/*----------------------------------------------------------------------------------
  @description 프레임 딜레이 함수
  @param scope : Object, 실행할 함수의 스코프
  @param callback : Function, 콜백함수
  @param delayFrame : Number, 딜레이프레임
*---------------------------------------------------------------------------------/
 
  public static function frameDelay():Void{
    var obj = arguments.shift();
    var func = arguments.shift();
    var delayFrame=arguments.shift();
 
   var p:Array=arguments;
   var mc:MovieClip=_root.createEmptyMovieClip("frameDelay",_root.getNextHighestDepth());
 
   mc.onEnterFrame=function(){
    trace(delayFrame);
    delayFrame--;
    if(delayFrame&lt;1){
 
     delete  this.onEnterFrame;
     func.apply(obj,p);
        this.removeMovieClip();
     }
   }
 
  }

ASAP Framework

asap본격적으로 asap framework 를 이용해서 패키지를 구성하기 시작했다.

그냥 IDE 없이 리팩토링하려면 적지 않은 작업이지만 eclipse를 사용하니 그나마 귀찮은 작업을 많이 덜수 있었다.

플래시에서도 framework 를 적용하여 어떤 일련의 과정을 모듈화하고 공통분모를 찾아 일반화했다는 점이 참 대단하다라는 생각이 든다.

이 framework 는 전반적으로 이벤트 지향프로그래밍의 성격이 강한것 같다.

다소 간단한 사이트를 개발하기에 부담스러울정도로 많은 내용의 코드가 걸리긴하지만 어떤 경우에도 적용가능하도록 확장성이 뛰어나다는 점에서 매력적인 부분이다.

package 구조

management : window,moviclip,sound

util : loader,xml,time,form, 등등 가장 덩치가 큰 패키지

project : 진행되는 프록젝트 클래스 파일

events : 이벤트 발생관련

Global Security Settings panel

플래시 8의 로컬 보안 변경사항에 따라 로컬상의 테스트를 html 상에서 하려면

경고창이 떠서 아주 성가셨다.

전역보안설정패널에서 c 드라이브 통채로 설정해 놓으면 된다.

전역 보안 설정 패널 가기