knowledge.lapasa.net

Greater Toronto Area Flash Platform Developer Blog

Type Conversions: Coercion vs. Casting

TAGS: None

Coercion
At run-time the Flash Player will implicitly convert the data type of a value into one that is suitable to be assigned.

For example, if number 5 is assigned to a variable of type Boolean, it will convert the 5 to a value of true and then store true in the variable.

Casting
In your code, you explicitly indicate you want the compiler to treat it as a different data type. To do this, you declare the data type as a function call with the value you wish to transform as the parameter.

For example,
var sEmergency:String = "911";
var nEmergency = Number(sEmergency);

On a related note, AS3.0 introduces a new operator called “as”. It work very much like type casting.

var zipCode:String = "90210";
var num:Number = zipCode as Number;
trace(num); // Output: 90210;

Source
Adobe Programming ActionScript 3.0

Notes: Dealing With Packages in AS3.0

TAGS: None

In AS2.0, you would structure the class files of a project as one .as file for each class. Each .as file would declare a single class.

// Circle.as
class Circle
{
public function Circle(){}; // constructor
}

Recall, packages in AS2.0 represented the directories where the source files resided. In AS3.0, this hasn’t changed either. If Circle.as was an ActionScript class file that was under the Shapes package which is under the Graphics package, you would need to prefix the class declaration with the fully qualified name of the package to satify the compiler:

// Graphics/Shapes/Circle.as
class Graphics.Shapes.Circle
{
public function Circle(){}; // constructor
}

What is new in AS3.0 is that each .as file now must have a package block. Adobe has made it clear that this is not just for the sake of the traditional establishment of namespace for a class’s elements so that it doesn’t collide with other objects that have identical element names. It is for added flexibility to the responsibilities a class will exercise. The new .as file format allows you to have one public class definition per source file but that source file can have many private support classes. The existence of these other classes are to support the one class that is declared public. Helper classes are declared outside of the package block. Furthermore, they cannot be acccessed publically.

// Circle.as
package Graphics.Shapes
{
public class Circle
{
public function Circle(){}; // constructor
}
}
class ColorCircle
{
// If ColorCircle class was declared inside the package block, the compiler would throw an error
}

Defining classes outside of a package will make that access specifier of type ‘internal’. This means it is only available to classes of the same package. The code inside ColorCircle would not be available to code outside of the Graphics.Shapes package.

Source
pg 42 - “Creating Packages” from Programming ActionScript 3.0

What I got out of the Cairngorm Microarchitecture

TAGS: None

Parts 1-3

  • Model Locator is a facade that components/views can plug into.
  • As the different views make modifications to the Model Locator object, the Model Locator will notify all those objects who have subscribe to it via Data Binding.
  • The Data Transfer Object Pattern desires to enforce the same object model among different tiers of an n-tier architecture. A RIA should adhere to representations of these concepts in the form of Value Objects rather than re-invent the wheel, localize it to a tier, and call it something else.
  • The article re-enforces the notion that there are three kinds of objects:
    • 1) Objects that interface with external systems
    • 2) Objects that interact with each other because they are intra-program
    • 3) Objects responsible with user gestures/interaction
  • Manage state on the client instead of the server-side

© 2009 knowledge.lapasa.net. All Rights Reserved.

This blog is powered by Wordpress and Magatheme by Bryan Helmig.