Archive for November, 2009

Invoking Constructors

0

RJ Regenold and I were discussing last night how we both strongly believe constructors should have extremely limited algorithms that simply invoke protected methods.

For instance, PureMVC’s Facade initializes the instance in the constructor

package org.puremvc.as3.multicore.patterns.facade
{
	import org.puremvc.as3.multicore.core.*;
	import org.puremvc.as3.multicore.interfaces.*;
	import org.puremvc.as3.multicore.patterns.observer.*;

	public function Facade( key:String )
        {
	     if (instanceMap[ key ] != null) throw Error(MULTITON_MSG);
	     initializeNotifier( key );
	     instanceMap[ multitonKey ] = this;
	     initializeFacade();
	}
}
package org.puremvc.as3.multicore.patterns.facade
{
	import org.puremvc.as3.multicore.core.*;
	import org.puremvc.as3.multicore.interfaces.*;
	import org.puremvc.as3.multicore.patterns.observer.*;

	public function Facade( key:String )
        {
	     if (instanceMap[ key ] != null) throw Error(MULTITON_MSG);
	     initializeNotifier( key );
	     initializeInstance();
	     initializeFacade();
	}

        protected function initializeInstance():void
        {
             instanceMap[ multitonKey ] = this;
        }
}

I would even argue that the Error checking / validation takes place in an init of some kind as well.

Another example is as follows
Instead of doing,

package
{
	import flash.display.Sprite;

	public class ViewUI extends Sprite
	{
		public function ViewUI()
		{
			super();
			width = 100;
			height = 200;
		}
	}
}

Do this

package
{
	import flash.display.Sprite;

	public class ViewUI extends Sprite
	{
		public function ViewUI()
		{
			super();
			init();
		}

		protected function init():void
		{
			width = 100;
			height = 200;
		}
	}
}

This practice becomes increasingly important in open-source projects. Moreover, this example may be limited but consider more complex constructors that you’ve seen or written yourself. The construction process should be divided into segments when possible.

UPDATE ( 01.13.10 ): Bill Sanders recently posted a good article about this exact topic!

Popularity: 13% [?]

Rasterize a Transformed Vector without Pixelation

0

How does one rasterize a transformed vector capturing it’s new dimensions without pixelation?

Note: This follows my previous post Matrix Not Synchronized

Challenge: To render a bitmap of a transformed vector display object without pixelation. Specifically, after a mx.controls.Text is transformed, a bitmap snapshot is needed to be taken of the new object including the dimensions.  I should note that the reason I am needing to get a bitmap snapshot is do to some shaping to the text.

Problem: However, doing so results in pixelation or resamples / renders the original dimensions of the transformed Text. It appears that flash.display.BitmapData::draw cannot get the new transformed display. In other words,  when a flash.display.InteractiveObject is scaled on the x axis (or any axis) using transform.matrix, flash.display.BitmapData::draw cannot capture the new dimensions of the display object.

Example: http://sources.novelastudios.com/flash/matrix_adustments/MatriciesAndDimensions.html#
When the application creation complete is fired a snapshot is made. Change the matrix width (transform.matrix.a) and then re-render a snapshot / bitmap. Notice it retains the original, non-transformed values. Therefore and considering it is a rastered snapshot, when the snapshot/bitmap is scaled it becomes pixelated. Example version was 1.1.0.0 that should this problem. Version 1.2.0.0 is a workaround for now showing the workaround.

Workaround: I give credit to Guy Stables (needs a link) and Alex Harui (http://blogs.adobe.com/aharui).  Essentially, the workaround is as follows:

  1. The InteractiveObject (we’ll call our target) needs to be placed in a container. In this example mx.controls.Text is placed inside a mx.core.UIComponent.
  2. The matrix transform is then applied to the target (eg mx.controls.Text)
  3. The dimensions of the container (eg the UIComponent that contains the Text/target) are then set to the  target’s pixelBounds dimensions.
  4. Finally, take the snapshot bitmap of the container (the UIComponent).

For a demonstration see the latest version 1.2.0.0 of the example.

More Information:
Also found at http://forums.adobe.com/thread/521432

Popularity: 20% [?]

Matrix Not Synchronized

0
I’m short on time right now and just want to post this
Basically, matrix transforms do not update dimensions, rotations, and coordinates of UIComponents / InteractiveObjects.
Adjust the width and notice that when you switch over to the Pixel Tab the width never updates.
Don’t believe me, then do a demo yourself.

Create a UIComponent transform the matrix’s a value and then inspect the width. Notice that there is no change

Note: With UIComponents you can change the explicitWidth when the transform takes place to perform a workaround. However, that’s not the point.

@Adobe Include event dispatching for matrix transforms!

Popularity: 9% [?]

Go to Top