Tag Archive for 'AS3.0'

Page 3 of 4

ActionScript 3.0 Tip of the Day

[퍼온글] 출처 : http://www.kirupa.com/forum/showthread.php?t=223798

The release of Flex Builder 2 is around the corner and though the next version of Flash is still a ways away, ActionScript 3 will be a big part of Flex 2 and the impending release of Flash Player 9 (which arrives with Flex). ActionScript 3 is the next step forward and to help with the transition (for those of you deciding to make it), I thought, since I’ve been working with AS3 a bit lately, I’d make a new Tip of the Day thread for ActionScript 3 to help people prepare. So here we go:

ActionScript 3 Tips and Tricks:

  1. 06-19-06: Change the frame rate of your movie
  2. 06-20-06: Class scope is now bound to class methods
  3. 06-21-06: Graphics Object and the Drawing API
  4. 06-22-06: New Variable Types
  5. 06-23-06: Display Objects
  6. 06-24-06: New Import Directive
  7. 06-25-06: Type Casting and the as Operator
  8. 06-26-06: Unique Class Variables
  9. 06-27-06: New MouseMove Behavior
  10. 06-28-06: The delete Keyword and Class Members
  11. 06-29-06: The Dictionary Class
  12. 06-30-06: Label Statements
  13. 07-01-06: Detecting When the Mouse Leaves the Movie
  14. 07-02-06: SimpleButton Instances
  15. 07-03-06: Commas in Shorthand Array Definitions
  16. 07-04-06: Package Block
  17. 07-05-06: Same-file Helper Classes
  18. 07-06-06: Access Attributes
  19. 07-07-06: Abstract Classes
  20. 07-08-06: The override Keyword
  21. 07-09-06: Using prototype
  22. 07-10-06: Regular Expression (RegExp) Support
  23. 07-11-06: Approach to Depth Sorting
  24. 07-12-06: Deep Object Copies with ByteArray
  25. 07-13-06: Similarly Named Instance and Static Properties
  26. 07-14-06: EventDispatcher
  27. 07-15-06: Events and Event Types
  28. 07-16-06: Writing Inline XML
  29. 07-17-06: Determine Instance Class or Superclass
  30. 07-18-06: super() Placement (Now Anywhere)
  31. 07-19-06: Determining Current Frame Label
  32. 07-20-06: Multiple Arguments in trace()
  33. 07-21-06: Calling Event Handlers without Events
  34. 07-22-06: URLRequest for URL Strings
  35. 07-23-06: XML vs. XMLDocument
  36. 07-24-06: Loading Text and XML with URLLoader
  37. 07-25-06: is Operator (vs instanceof)
  38. 07-26-06: Flash 9: Timelines as Classes
  39. 07-27-06: RegExp: Email Validation
  40. 07-28-06: Render Event
  41. 07-29-06: XML: @ Operator for Attributes
  42. 07-30-06: Event Propagation Support
  43. 07-31-06: Get Sound Spectrum Information
  44. 08-01-06: Number() Conversion No Longer Interprets Octals
  45. 08-02-06: Garbage Collection: Reference Counting & Mark and Sweep
  46. 08-03-06: Weak References
  47. 08-04-06: Flash 9: BitmapData and Bitmaps from the Library
  48. 08-05-06: Changes in typeof
  49. 08-06-06: getBounds() vs getRect()
  50. 08-07-06: for..in and for each..in

_______________________________________

Additional Resources:

Download:

Flash Professional 9 ActionScript 3.0

[퍼온글]

Adobe Flash Professional 9 ActionScript 3.0 Preview provides registered users of Flash Professional 8 with early access to the new ActionScript 3.0 language and the ability to publish to the newly-released Flash Player 9. ActionScript 3.0 and the new ActionScript Virtual Machine introduced with Flash Player 9 are among the most signficant advances in the history of Flash. These new advancements, made in Flash Player 9, provide a more robust programming model, achieve standards compliance, and deliver ground-breaking performance improvements.

The Flash Professional 9 ActionScript 3.0 Preview is the only planned “preview release” of the next version of the Flash authoring tool before the final version ships in 2007. The only “new” features exposed in this very early preview of Flash 9 are those related to publishing ActionScript 3.0 content to Flash Player 9. This includes integration of the new ActionScript 3.0 compiler, the new “Document Class” feature which allows users to assign a class to the main timeline, and a new publish target for Flash Player 9. There are other useful features planned for ActionScript development but they are not being made publicly available at this time.

A universal binary version of Flash Professional 9 ActionScript 3.0 Preview for Intel-based Macintosh computers is not planned to be made available on Labs. A universal binary version is planned for the final release.

Read more about Flash Player 9 and ActionScript 3.0.

Runtime Exceptions And Types

In ActionScript 2.0, type annotations were primarily a developer aid; at runtime, all values were dynamically typed. In ActionScript 3.0, type information is preserved at runtime, and utilized for a number of purposes. The Flash Player performs runtime type checking, improving the system’s type safety. Type information is also used to represent variables in native machine representations, improving performance and reducing memory usage.

단순히 개발자의 코드 가독성을 위한 도구였던 데이타 타입 설정이 As3.0 에서는 진정한 데이타 타입으로서 기능하게 되었다. 컴파일 타임에서의 데이타 타입의 체크에서 끝났던 것이 이제는 런타임에서도 타입체크가 가능하다.

이로써 실시간 예외처리도 가능해졌다. 플래시에서 가능 취약했던 부분인 런타임 디버깅이 비약적으로 발전했다. 이제보니 플래시가 스크립트 언어라고 하기엔 너무 커진것 같다는 생각이 든다..^^

Delegation in AS3.0

Event handling is simplified in ActionScript 3.0 thanks to its built-in delegation. In ActionScript 2.0, method closures would not remember what object instance they were extracted from, leading to unexpected behavior when the method closure was invoked. The mx.utils.Delegate class was a popular workaround; to use it, you would write code as follows:

myButton.addEventListener(“click”, Delegate.create(this, someMethod));

This class is no longer needed, since a method closure will now automatically remember its original object instance. Now, one can simply write:

myButton.addEventListener(“click”, someMethod);

꼭 바뀌었으면 하는 것이 AS3.0 에서 개선되었다. AS2.0 에서는 중첩된 메서드에서 부모 오브젝트에 접근하지 못했다. 그래서 지역변수를 이용하거나 mx.utils.Delegate 클래스를 사용해 오브젝트 스코프를 지정했는데 이젠…이런게 필요없다.

자동으로 오브젝트를 기억한다고 한다…앞으론 좀더 코드가 간결해질듯 싶다.^^

E4X XML API in AS3.0

ActionScript 3.0 features a full implementation of ECMAScript for XML (E4X), recently standardized as ECMA-357. E4X offers a natural, fluent set of language constructs for manipulating XML. Unlike traditional XML parsing API’s, E4X makes XML feel like a native data type of the language. E4X streamlines the development of applications that manipulate XML by drastically reducing the amount of code needed. You can learn more about the E4X specification here:

http://www.ecma-international.org/publications/files/ECMA-ST/ECMA-357.pdf
AS3.0 에 새롭게  E4X(ECMAScript for XML) 를 지원한다. E4X 는 XML을 관리하기 위한 모든 언어를 제공한다. 이젠 플래시에서도 제한된 xml 에서 탈피해 좀 더 효율적인 코드작성이 가능하다.

따로 파서를 만들어 쓰고 있지만  워낙 xml 쓰는 방법이 다양해 정형화된 방법을 찾는데 쉽지 않았다.

시간이 되면 AS2.0 방식도 아래와 같은 방법으로 사용해서 파서를 따로 만들어 쓰는것도 좋은 방법인듯 싶다.

AS3.0 에서부터는 xml 노드 구조만 알면 이제부터 아주 쉽게 데이타 파싱이 가능하다.

내장되어있는 파서인 만큼 특별한 코드가 필요없다.

xml 데이타를 통해 노드구조를 접근하면 파서가 알아서 데이타를 추출해 준다. 또한 조건 검색을 통한 데이타 검색도 가능하다.

AS3.0 ….. 암튼 무척 기대된다.

 
package {
	import flash.display.MovieClip;
	import flash.util.trace;
	public class E4XExample extends MovieClip {
 
		public function E4XExample() {
 
			var employees:XML=<staff>
 
			 <employee id="1" status="active">
 
			 <name>Christian Cantrell</name>
 
			 <position>CEO</position>
 
			 <startDate>12/1/2001</startDate>
 
			 </employee>
 
			<employee id="2" status="active">
 
			  <name>Danny Dura</name>
 
			  <position>Developer</position>
 
			  <startDate>4/9/2003</startDate>
 
			         </employee>
 
			<employee id="3" status="contractor">
 
			  <name>Mike Chambers</name>
 
			  <position>Director</position>
 
			  <startDate>8/11/1999</startDate>
 
			</employee>
 
			<employee id="4" status="active">
 
			  <name>Scott Fegette</name>
 
			  <position>President</position>
 
			  <startDate>2/4/1889</startDate>
 
			</employee>
 
			</staff>;
			//All employees' names (as an XMLList)
			trace(employees.employee.name);
 
			// The first employee's name
			// Christian
 
			trace(employees.employee[0].name);
 
			// All IDs (as an XMLList)
			// 1234
 
			trace(employees.employee.@id);
 
			// The name of the employee with an ID of 2
			// Danny Dura
			trace(employees.employee.@id==2.name);
 
			// The employee with the name "Christian Cantrell"
			// Returns an XMLList
			trace(employees.employee.name=="Christian Cantrell");
 
			// Employee #3's start date
			// 8/11/1999
			trace(employees.employee.@id==3.startDate);
 
			// All contractors (as XMLList)
			trace(employees.employee.@status=="contractor");
 
			// All contractors' names (as XMLList)
			trace(employees.employee.@status=="contractor".name);
 
			// All employees with IDs less than or equal to 2
			// Returns an XMLList
			trace(employees.employee.@id<=2);
 
			// Iterate through all start dates
 
			var item:XML;
			for each (item in employees..startDate) {
				trace(item);
			}
		}
	}
}