Tag Archive for 'Flash'

URL Encoding

escape 함수
escape(expression:String) : String
매개 변수를 문자열로 변환하거나 영숫자가 아닌 모든 문자를 % 16진수 시퀀스로 바꾸는
URL 인코딩 형식으로 인코딩합니다. URL 인코딩 문자열에서 사용되면 퍼센트 부호(%)는
이스케이프 문자를 시작하는 데 사용되고 이는 모듈러스 연산자(%)와 동일하지 않습니다.

URL인코딩은 웹에서 흔히 볼수 있는 것으로
“kimkijeung%20vkimone”를  “kimkijeung%vkimone” 이런식으로 인코딩을 하는 것을 말한다.


외부 데이터와 연동을 시킬 때는 꼭 사용해야 에러를 막을 수 있다. 반대로 바꿔 주는 함수로는 unescape 가 있다.


예) a=escape(“김기정”);
    trace(a);


/* 이 구문을  실행하면 output 창에


%EA%B9%80%EA%B8%B0%EC%A0%95


과 같이 나온다. */


다른 나라 사람의 언어 환경을 고려하지 않는다면 별 해당사항이 없겠다.
하지만 각 나라마다 고유의 언어 셋이 있어 나라 별로 컴퓨터에서 사용하는 언어가 다르다.
플래시에서 그냥 static field 를 사용하여 작성한다면 그냥 적은 그대로 보이겠지만
외부 데이타를 가져 와서 보여 줘야 한다면 반드시 주의할 점이 있다.

플래시에서의 정보는 유니코드(utf-8) 로 입출력된다. 플래시가 기본적으로 외부 텍스트를 해석할테
System.useCodePage 값을 true 로 설정하지 않느다면 말이다.

useCodePage  는 Flash Player가 외부 텍스트 파일을 해석할 때 유니코드를 사용할 것인지 현재 운영 체제의 기존 코드 페이지를 사용할 것인지 여부를 지정하는 부울 값이다
간혹가다 유니코드로 인코딩 되지 않은 외부데이타를 불러올때 플래시에서 깨져서 보이는 경우가 있다. 이럴때 useCodePage 값을 true 로 설정하면 현재 운영체제에 맞는 코드 페이지를 사용하여 텍스트가  재대로 보이게 된다.

하지만, System.useCodepage를 true로 설정하는 경우, 현재 운영 체제의 기존 코드 페이지에 외부 텍스트 파일에 사용된 문자가 포함되어 있어야만  텍스트를 표시할 수 있습니다. 예를 들어, 중국
어 문자가 포함된 외부 텍스트 파일을 로드하는 경우, CP1252 코드 페이지에는 중국어 문자
가 들어 있지 않기 때문에 이 페이지를 사용하는 시스템에서 이 문자들이 표시되지 않는다.

모든 운영 체제 사용자가 SWF 파일에 사용된 외부 텍스트 파일을 볼 수 있게 보장하려면 모
든 외부 텍스트 파일을 유니코드로 인코딩하고 System.useCodepage를 기본값인 false로 설
정해야 한다.

하지만 이걸로 모든 문자가 표시되는 것이 아니다. 플래시에서 데이타를 저장하고 그걸 다시 불러올때 이런 방식으로 해도 데이타는 원하는 값을 표시할수 없다.
반드시 특수문자나 다른 나라 언어를 저장할때는 텍스트 정보를 URL 인코딩 방식으로 변환하여 보내야 한다.

여기서 escape, 와 unescape 를 사용하면 된다.
그리고 반드시 URL 인코딩을 사용하려면  System.useCodepage 는 기본값인 false 로 놓아두어야 한다. 그렇지 않으면 각 나라의 운영체제의 코드 체계의 문자들의 바뀌어져 인코딩 되어 다른 결과가 보여질 것이다.

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

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형식으로 작성하긴 하지만 빠쁠땐 그냥 넘어가는 경우도 있는데 나중을 위해 좀더 부지런해져야 할 것같다.

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();
     }
   }
 
  }