Tuesday, July 10, 2007

Introduced with ActionScript 3.0 and Adobe Flash Player 9, ECMAScript for XML (E4X) offers new ways to retrieve data from XML in Adobe Flash applications. In this article I examine how you can use E4X to fetch data out of an XML object within an application in real time—processing only the information required to run the application. This strategy improves the performance of Flash applications by reducing unnecessary overhead and data loading.

E4X: A welcome addition to Flash Player

The release of Flash Player 9 includes a new virtual machine called ActionScript Virtual Machine 2 (AVM2), which increases player performance. In addition, improvements to the ActionScript language in ActionScript 3.0 offer Flash developers new functionality when creating Flash applications.

Note: Read the AVM2 overview (PDF, 401k ) for more information about the instructions, associated data structures, and file format supported by ActionScript Virtual Machine 2.

One of those improvements was the adoption of ECMAScript for XML (E4X), a part of ECMAScript—the standardized scripting language popularly implemented as JavaScript. ActionScript is based on ECMAScript and Adobe is one of the contributors to the ECMAScript standard.

E4X is an extension to ECMAScript that adds XML as a native data type, adding operators like the dot (.) and the attribute identifier (@) to search and filter data. For ActionScript developers, this means XML is now a native data type in ActionScript 3.0. XML now comes with its own set of classes to manage and access data, making it much easier for Flash to access data within XML structures.

E4X offers faster and more logical access to XML data consumed by ActionScript 3.0 applications. You can use it at runtime to pull data directly from an XML object, which eliminates the need to write a specialized parser. Previously XML data had to be transformed from an XML packet into structured native data types, such as arrays of objects, in order for the application to use the data. This process is now much more intuitive and XML data is easier to consume using ActionScript 3.0.

E4X operators

If you are familiar with the basics of accessing data within an array of objects using either square brackets ([]) or dot notation (.), you'll immediately recognize some of the syntax used when working with E4X. In addition to these operators, the attribute identifier (@) is used when performing E4X operations.

In the example below, a string of characters is data typed as an XML object:

var myXML:XML =
 
   Frank
   Bacon
   
  fbacon@company.com
 
 
   Chris
   Wren
   cwren@company.com
 

In the code example below, the E4X operators I previously discussed are used to access data contained within the XML object:

trace(myXML.employee[0].fname); //
  Output: Frank
trace(myXML.employee.(@id=="2").email);
  // Output: cwren@company.com
trace(myXML.employee.(lname=="Bacon").email);
  // Output: fbacon@company.com

The first trace statement displays the first name of the employee in the first node of XML.

The second trace statement filters data by the id attribute to find a case where the id value is equal to "2."

The third trace statement filters data by finding a node whose value is equal to "Bacon."

Note: These filters are case-sensitive. Comparing the string "bacon" would not result in the same output.

You can use a for loop to iterate through all the nodes of the XML file. In the code example below, the loop repeats and outputs each employee's first name, last name, and e-mail address until the data for both nodes has been accessed:

for each ( var property:XML in myXML.employee ) {
 trace(property.fname + " " + property.lname);
 trace(property.email);
 trace("--------------------");
}

This article was previously posted by Andrew Muller on http://www.adobe.com/devnet/flash/articles/filtering_data_e4x.html

Monday, July 9, 2007

createEmpty MovieClip is no more on AS3

One of the widely used script is actionscript 2.0 createEmptyMovieClip is no more available on actionscript 3.0. Along with createEmptyMovieClip, attachMovieClip, dupliCateMovieClip and few others are also rewrited as addChild script. No the the actionscript programmers like me have to adapt with the new language. The actionscript 2.0 and actionscript 3.0 are compared below.

Actionscript 2.0
class Myclip extends MovieClip {
var myobject:MovieClip;
public function Myclip() {
myobject = _root.createEmptyMovieClip("myobject", this.getNextHighestDepth());
myobject.loadMovie("myswf.swf");
}

}


Actionscript 3.0
package {
import flash.display.MovieClip;
import flash.display.StageAlign;
import flash.display.StageScaleMode;
import flash.util.trace;
public class Myclip extends MovieClip {
[Embed(source='myswf.swf')] public var MySwf:Class;
public function Myclip() {
stage.align = StageAlign.TOP_LEFT;
stage.scaleMode = StageScaleMode.NO_SCALE;
var swf:MySwf = new MySwf();
addChild(swf);
trace(swf);
}
}

}

Using the class Tween and TweenExtended

The ActionScript offers ways to develop extremely powerful dynamic animations without using timeline. It has diverse classrooms of the proper Flash and others developed by third.

Class TweenExtended
Before initiating make the download the last version of the TweenExtended class in the site
http://www.sqcircle.com/downloads/ and installs for Macromedia Extension Manager. After the installation must appear a new option in help of the Flash.
The syntax of the class is the following one:

Actionscript:
import mx.transitions.easing.*;
import mx.transitions.TweenExtended;
var _tween = new TweenExtended(target, props, easeFunc, strt, end, dur, useSecs, bezierPoint1, bezierPoint2);
/*
constructor for Tween Exdended class
target: reference - the object which the Tween targets
props: array - names of the properties (in obj) that will be affected
easeFunc: function - the type of easing equation to be used [import easing equations: import mx.transitions.easing.*;]
strt: array - the starting value of props
begin: array - the ending value of props
dur: number - the length of time of the motion; set to infinity if negative or omitted
useSecs: boolean - a flag specifying whether to use seconds instead of frames

*optional bezier parameters*
To use the Bezier tween both parameters must be entered and must be used in conjunction with mx.transitions.easing.Bezier;
has three easing methods: tweenQuadBez, tweenQuadBezThru, tweenCubicBez

bezierPoint1: number - numerical x position value
bezierPoint2: number - numerical y position value
*/
We go to see some examples:
It creates a new archive in the Flash, later creates one movieclip (a ball for example) giving the name of instance of "ball_mc". Example with metodo TweenExtended.continueTo ():

Actionscript:
import mx.transitions.easing.*; // optional: import all easing equations,
// or choose from: Back, Bounce, Elastic, Regular, Strong, None
import mx.transitions.TweenExtended;
var _tween:TweenExtended = new TweenExtended(ball_mc, ["_x","_y","_alpha"], Regular.easeInOut, [ball_mc._x, ball_mc._y, ball_mc._alpha], [50, 350, 50], 5, true);
//
_tween.onMotionFinished = function(obj) {
_tween.continueTo([150, 50, 90],5);
}

It sees the example working.

Example with method TweenExtended.yoyo():


Actionscript:
import mx.transitions.easing.*; // optional: import all easing equations,
// or choose from: Back, Bounce, Elastic, Regular, Strong, None
import mx.transitions.TweenExtended;
var _tween:TweenExtended = new TweenExtended(ball_mc, ["_x","_y","_alpha"], Regular.easeInOut, [ball_mc._x, ball_mc._y, ball_mc._alpha], [50, 350, 50], 5, true);
//
_tween.onMotionFinished = function(obj) {
_tween.yoyo();
}
It sees the example working

Example with method TweenExtended.addListener():


Actionscript:
import mx.transitions.easing.*;
// optional: import all easing equations,
// or choose from: Back, Bounce, Elastic, Regular, Strong, None
import mx.transitions.TweenExtended;
//
// EventListener Object:
var eventListener:Object = new Object();
eventListener.onMotionStarted = function(obj) {
trace(obj.obj+" - onMotionStarted - eventListener");
};
eventListener.onMotionFinished = function(obj) {
trace(obj.obj+" - onMotionFinished - eventListener");
};
//
//
var _tween:TweenExtended = new TweenExtended(ball_mc, ["_x", "_y", "_alpha"], Regular.easeInOut, [ball_mc._x, ball_mc._y, ball_mc._alpha], [50, 350, 50], 5, true);
//
// register the listener:
_tween.addListener(eventListener);

It sees the example working

Example with method TweenExtended.loop:


Actionscript:
import mx.transitions.easing.*;
// optional: import all easing equations,
// or choose from: Back, Bounce, Elastic, Regular, Strong, None
import mx.transitions.TweenExtended;
var _tween:TweenExtended = new TweenExtended(ball_mc, ["_x", "_y", "_alpha"], Regular.easeInOut, [ball_mc._x, ball_mc._y, ball_mc._alpha], [50, 350, 50], 5, true);
//
_tween.loop = true;
//
_tween.onMotionLooped = function(obj) {
trace(obj.obj+" - onMotionLooped");
};

It sees the example working.

Another sufficiently interesting class is the TransitionManager of the proper Flash. With it we can create transistions saw ActionScript and with effect that a certain time would take to make for timeline. We go to see an example of as to use the TransitionManager class the same using movieclip "ball_mc" used in the examples above:

Actionscript:
mx.transitions.TransitionManager.start(ball_mc, {type:mx.transitions.Zoom, direction:mx.transitions.Transition.IN, duration:1, easing:mx.transitions.easing.Bounce.easeOut});

It sees the example working.

Documentation of classe TransitionManager
http://livedocs.macromedia.com/flash/8/main/wwhelp/wwhimpl/common/html/wwhelp.htm?context=LiveDocs_Parts&file=00004085.html

Classe Tween
http://www.kirupa.com/developer/actionscript/tween.htm


Classe Tween Extended
http://www.sqcircle.com/downloads/


This article was previously posted by Leonardo França on http://www.leonardofranca.com.br/index.php/2006/01/06/using-the-class-tween-and-tweenextended/en/#more-180

Wednesday, July 4, 2007

How to work with the clips now?

The differences between AS1 and AS2 are small, some of API of player (for example bitmap filters and External Interface) and emulation OOP of medium at the stage. This is precisely emulation, compiles, assembles from existing AS2 code AS1. You will look to the parameters of publication, select Flash Player 6 and you will be convinced that medium it predalagayet publication in two languages AS1 and AS2.

Many flash users speak that they "code on AS2", but majority of them do not understand what is OOP. They have some ideas about this, but write programs in the personnel of clips and consider "classes" excess navorotom of large sense in which they see. OOP ideology - key moment, which differs AS1 from AS2.
If write programs in the clips, it means you code on AS1.

If AS1 - your first language of programming. That to pass on Action Script 3 you will be more complexly. SINCE in your brain (as earlier in my) there are harmful bends of the abstract model Movie Clips.

If you worked on Action Script 2 the entire somewhat simpler, because of the principles OOP, by which it is possible to learn in Action Script 2.
All flash AS1 users, will confuse the new model of work with the clips.

Earlier to programming clip from the library was thus:

clip.attachMovie('linkageId', 'clipName', depth)

1. Code the new copy of symbol linkageId
2. they created the new variable clipName in clip clip.
Process is not sufficiently customary for the programmer. By two line literals we create incomprehensible type variable in object clip.

In Actions Script 3 logic more greatly standards.
Which to create some graphic element and to place it on the scene is necessary:

1. To create new symbol in the library and to draw something in this symbol.
2. To associate the created symbol with the class:
Simply click by right button on the symbol in library, select Linkage. In the opened window check Export for ActionScript.
In the text field "Class" introduce the name of class.
3. to create the instance of class and to program where is necessary by the method addChild().

You will allow they created in the library symbol they associated it with class Square.

package

{

import flash.display.Sprite;

public class Board extends Sprite

{

public function Board()

{

var aSquare:Square = new Square()

this.addChild(aSquare);

}

}

}

Saturday, June 30, 2007

Migrating from Flash 8 to Flash CS3

Adobe® Flash® CS3 Professional introduces many new and changed elements in the workspace that improve the way you work with Flash. It also features new tools you can use to create exciting new applications, or integrate with other components of Adobe Creative Suite 3.

This article discusses the new features in Flash CS3 Professional and how they compare to similar features in Flash 8, or how they have changed. Therefore, it's written with the assumption that you're already somewhat familiar with Flash. If you are a Flashthusiast ready to update to Flash CS3, read on. You will learn about the changes you need to know about when starting out with the latest version of Flash, whether you want to draw with the enhanced Pen tool or write ActionScript™ 3.0 code. Specifically, this article covers:

  • Changes made to the Flash workspace, such as new ways to manipulate panels and great new interface features. You also learn how to optimize your workspace to make working with Flash easier.
  • New features in the Flash authoring tool, such as control over the color of your bounding boxes, new copy-and-paste functionality, and changes to 9-slice scaling.
  • Improvements made to file import, such as support for PSD and AI files. You also learn about new ways to integrate products, such as the enhanced workflow between Flash and Adobe® Device Central CS3.
  • Improvements to the drawing tools in Flash, such as enhancements to the Pen tool, and the brand new primitive drawing tools that let you create shapes easier.
  • Improvements to the video components and cue points in Flash and Flash Video Encoder.
  • The new ActionScript 3.0 components, including how they compare to the V2 Components found in Flash 8. You will also see a side-by-side comparison of how to create the same components application in ActionScript 2.0 and ActionScript 3.0.
  • Improvements to the debugger and coding tools in Flash, and changes to ActionScript. You will find a side-by-side comparison of ActionScript 2.0 code and ActionScript 3.0 code. You'll also learn about, and how to use, a document class in an ActionScript 3.0 application.
This article is previously posted on http://www.adobe.com/designcenter/flash/articles/flacs3_migration.html by Jen deHaan

Wednesday, June 20, 2007

Flash CS3 with new opportunities and challanges

After acquiring Macromedia Inc. by Adobe Systems Inc, first time Adobe bring the latest version of Flash with its identity as Adobe Flash CS3 and its scripting language as AS3.