Moments of Flash, ActionScript, Flex

Discuss, challenge, inspire, connect, discover...

Subscribe
Add to Technorati Favourites
Add to del.icio.us
Nov 19, 2009

New Home

Posted by Unknown

Flash Moments has moved to http://flashmoments.novelastudios.com

Nov 10, 2009

Rasterize a Transformed Vector without Pixelation

Posted by Unknown

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

Nov 2, 2009

Matrix Not Synchronized

Posted by Unknown

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!

Oct 9, 2009

Funny Compiler Check Bug

Posted by Unknown

Evidently, to the compiler the following is a big difference:

Passes
[actionscript]
return [
                 {label:"MyriadPro",styleName:"textDefault"}
                ,{label:"Albertus",styleName:"textAlbertus"}
            ];
[/actionscript]

FAILS
[actionscript]
return
[
                 {label:"MyriadPro",styleName:"textDefault"}
                ,{label:"Albertus",styleName:"textAlbertus"}
            ];
[/actionscript]


[error message]
Severity and Description    Path    Resource    Location    Creation Time    Id
1065: Metadata attributes cannot have more than one element.    ProjectName/src/com/novelastudios/examples    FontsUtil.as    line 8    1255105753861    1317796

[/error message]

If you couldn't tell the difference, all that is different is the bracket starts on the same line as the return in the first example. Whereas, in the second, it is on the following line.

I'm actually curious if there is a reason to the humor in this perceived "bug." I'm going to search for a post in Adobe's JIRA for Flex

My opinion is that the following is a big bug.

When serializing/cloning an object that has required constructor parameters, you receive an error telling you the arguments are incorrect. Note: the following is just an example using a "native" flash class. Really, you should never have to serialize or clone an Event, so please just see it as an example class as the type of class isn't the point.

[actionscript]
import flash.net.registerClassAlias;
import flash.events.Event;
import mx.utils.ObjectUtil;

flash.net.registerClassAlias("flash.events.Event",Event);
var event:Event = new Event(Event.CHANGE);
var eventClone:* = ObjectUtil.copy(event);
trace(eventClone is Event)
[/actionscript]

[result]
ArgumentError: Error #1063: Argument count mismatch on flash.events::Event(). Expected 1, got 0.
at flash.utils::ByteArray/readObject()
at mx.utils::ObjectUtil$/copy()
at Untitled_fla::MainTimeline/frame1()
[/result]

As noted by Nutrox, "All constructor parameters need a default value. You can't pass values directly to an object's constructor when it is restored from serialised data because Flash creates an instance of the object automatically before calling the object's readExternal() method."




What are your thoughts? I'm interested in striking a conversation about this.

Jun 27, 2009

Hidden $addChild for Flex Components

Posted by Unknown

Ever try to add a DisplayObject to a Flex Component? If you have, you know the run-time engine will complain about a type conversion (Adobe casts DisplayObjects to IUIComponents). Well, there is a hidden $addChild for UIComponents. To utilize simply add use namespace mx_internal; to the beginning of your script. Now you can use $addChild.

For more information, check out http://www.boostworthy.com/blog/?p=224.

I came across a bug where when you set the scrollRect of a DisplayObject and get a dimension, within the first few mil/nano-seconds it reports the correct width and height. However, after that the reported width and height is the scrollRect's width and height. This to me is a bug considering you can not request the object to tell you it's full dimensions any longer.

Take a look at http://www.kirupa.com/forum/archive/index.php/t-256884.html and here is the solution http://usecake.com/lab/find-the-height-and-width-of-a-sprite-with-a-scrollrect.html