Arbitrary Thoughts

Introducing ActionScript Blocks (ASBlocks)

Being in the time of changes, I as many others have taken a good look at my toolbox and taken up to review if there was anything in there I 1) could take out and hang back on the wall or 2) should put in my toolbox which wasn’t already there…

No need to worry, this is not another rant in the direction wether Flash/Flex is dead or not, Im merely sharing one of my more recent findings…

The ASBlocks project is a framework written in ActionScript3 AND Java to read and write ActionScript3 source code (classes, interfaces, functions and namespaces).

ASBlocks comes in 2 distinct flavors; ActionScript3 and Java. This means if you are looking to build a tooling application in Adobe Flex/AIR you can use the ActionScript as-blocks framework project. If you want a high powered, multi-threaded application backed by Java, use the jas-blocks framework project. Both frameworks implement the same ASBlocks Document Object Model (DOM). So shifting back and forth only has the learning curve of knowing each language.

Basically, all of this is referring to the processing and parsing of programming languages, relative to Input and Output from one processor to another in the compile or language processing chain. This project could be used to bridge the gap between Flex and other output technologies than AVM Bytecode (ActionScript Virtual Machine Bytecode) which is the current output since practically the only target runtime supported at the time of writing by Flex is Flash Player and AIR (Other AVM’s exist than Adobe Flash Player as you can see documented in other of my posts).

Now, things like ASBlocks can help change the landscape of runtimes being targeted by Flex, once you have an AST (Abstract Syntax Tree) for ActionScript in Java, its fairly straight forward to start using the AST to target various runtimes, such as e.g. HTML, CSS and JavaScript.

Flex’s MXML is by far the superior domain specific language for UI representation available for production today, and backed by a strong language such as ActionScript, it continues to make Flex a really interesting platform for building UI, regardless of speculations against the future of Flash Platform.

When Adobe donates Flex, Falcon (NextGen Flex Compiler) to Apache, its interesting and we will see more of this kind of topic as the maintenance and further development of Flex is put in the hands of the Global Developer Community, which I expect will help to speed up the evolution of Flex as well as spark of a new generation of DSL’s for abstracting complex UI patterns…

Check out ASBlocks…
http://labs.teotigraphix.com/doku.php/asblocks

ASBlocks is incepted and developed by Michael Schmalle, owner of Teoti Graphix…
@TeotiGraphix

 

Tools

"Enterprise JavaScript with Jangaroo" – a presentation 3 weeks ago at PLASTIC 2011

In order to get started understanding exactly what Jangaroo is trying to achieve and how far they actually are, this presentation from 3 weeks ago does a great job… take the 3 minutes it will take to run it trough, even one didn’t attend the session, the presentation speaks for itself…

ActionScript 3.0, Adobe Flex

Save Image As… now as a separate tag

James Ward created a clever way of adding a “Save Image As…” feature to an image in Flex.


SaveImageAs

However clever, in my case I really wanted to avoid having to subclass the Image class specifically, so I created an MXML tag which would take the Image instance as an argument instead.

The source code looks like this…

package org.hello.saveimageas
{
	import flash.events.ContextMenuEvent;
	import flash.net.FileReference;
	import flash.ui.ContextMenu;
	import flash.ui.ContextMenuItem;
	import flash.utils.ByteArray;

	import mx.controls.Image;
	import mx.core.IMXMLObject;

	public class SaveImageAs implements IMXMLObject
	{
		private var _target:Image;
		private var _label:String = "Save Image As...";

		public function SaveImageAs()
		{
			super();
		}

		public function initialized(document:Object, id:String):void
		{
			// empty for now
		}

		protected function saveImageAs( event:ContextMenuEvent ) : void
		{
			var tba:ByteArray = new ByteArray();
			this.target.content.loaderInfo.bytes.readBytes(tba, 0, ( this.target.content.loaderInfo.bytes.length - 17 ) );
			tba.position = 49;

			var ba:ByteArray = new ByteArray();
			while (tba.bytesAvailable)
			{
				ba.writeByte(tba.readUnsignedByte());
			}

			var fr:FileReference = new FileReference();
			fr.save( ba, this.target.source.toString() );
		}

		[Bindable]
		public function get target() : Image
		{
			return this._target;
		}

		public function set target( value:Image ) : void
		{
			this._target = value;

			if( this.target != null )
			{
				var targetContextMenu:ContextMenu = this.target.contextMenu != null ? this.target.contextMenu : new ContextMenu();
				targetContextMenu.hideBuiltInItems();

				var item:ContextMenuItem = new ContextMenuItem( this.label );
				targetContextMenu.customItems.push(item);

				item.addEventListener( ContextMenuEvent.MENU_ITEM_SELECT, saveImageAs );

				this.target.contextMenu = targetContextMenu;
			}
		}

		[Bindable]
		public function get label() : String
		{
			return this._label;
		}

		public function set label( value:String ) : void
		{
			this._label = value;
		}
	}
}

A basic usage of it could look something like this…

 
<s>

	

	
		
	

</s>

Be sure to check out the original implementation by James Ward… it might suite your needs better…
http://www.jamesward.com/blog/2009/07/09/flex-example-right-click-save-image-as/

Thomas Burleson has already cornered this approach – as “Flex Behavior Injection”… check it out…
http://www.gridlinked.info/flex-behavior-injection/

The above modification to James Wards’ original contribution has been added to the “unsponsored” framework from where you can obtain it via SVN…
http://code.google.com/p/unsponsored/

ActionScript 3.0

Google Wave… likely now not waporware, and now with an AS API

Google Wave will now suddenly not become waporware… I never thought it would, however lots or credible people have spoken about the chance that Google Wave would either never see the day of light or if then, only for a short time.

Google Wave Logo

If you want to get started with utilizing the Google Wave API’s and like I am currently, mostly building systems based on ActionScript and Flex, you don’t need to start implementing your own delegate API Google’s API, a couple of guys from the Google Developer Community has created a simple ActionScript implementation already.

Check it out…
http://code.google.com/p/wave-as-client/

A couple of notes…
* it uses ExternalInterface to call the actual JavaScript implementation (so no new communication logic)
* its released on the Apache License
* its very recent and active (last commit at the time of this post was 28 hrs ago)

ActionScript 3.0

A fun way to open a native window in AIR with MATE

Sometimes when coding it happens that you stumble on something which just strikes you as funny (sometimes for apparently no reason whatsoever).
One such experience happened today when I was coding an AIR client with MATE and I had to open a new NativeWindow.
It should be noted that I for this implementation am experimenting with ridding myself of using Managers (no other motivation than curiosity about will come out in terms of code design and architecture).

Well, the thing that amused me was to use a PropertySetter. This is due to the fact that you have to set the “visible” property in order to actually show the window. However, you also have to pass an object of the type “NativeWindowInitOptions” to the constructor.

The code eventually can be written like this…


<s>

	<s />

	
		
	

</s>



	

		
			
		

	



ActionScript 3.0, Adobe Flex

MATE CacheSetter.. a quick and dirty introduction

One of the newer classes in the MATE Flex Framework yet to be documented is the CacheSetter.
It’s nothing overly fancy, but it does exactly what it promises… it allows you to set the Cache from an ActionTag.

Let’s examine the code below… it’s a standard MATE EventMap with a couple of eventhandlers which offers to exit an AIR application when the User clicks anywhere on it… the applications for such a feature might be quite limited, but that’s what I could think of at 4:40 AM in Bangkok after almost 2 hours of being teleconferencing with the Flex Team sitting in California and it proves the point with the CacheSetter close to a minimal implementation.

NativeSystemEventMap.mxml




	
		
	

	

		
			
		

		
			
		

	


For the sake of completion, I will also bring the code to the AIR application itself…


<s>

	
		
	

</s>

One of the more interesting and intricate details (and eventually why this exercise is interesting), is to see that it uses the Class reference as the cacheKey and that you eventually would be able to use any class or hashable object and chain as the cacheKey. If the cacheKey is NOT set explicitly it will default to use the class type of the Generator attribute, but if you are working with MATE the Cache class is one of the classes it makes the most sense to take an extra look at…

CacheSetter (Source)
http://code.google.com/p/mate-framework/source/browse/trunk/src/com/asfusion/mate/actions/CacheSetter.as

Cache (Source)
http://code.google.com/p/mate-framework/source/browse/trunk/src/com/asfusion/mate/core/Cache.as

Cache (Documentation
http://mate.asfusion.com/api_docs/com/asfusion/mate/core/Cache.html

ActionScript 3.0

ActionScript API for Adobe Wave Service

While I was experimenting with the new Adobe Wave Service from Adobe… I decided to take some of the experimental code and create a reusable library.
It has a basic implementation handling authentication as well as broadcasting notifications.

2009-07-09_0612

I have named the project “asadobewave” which roughly stands for ActionScript Adobe Wave and I have made it available via the Google Code under the Mozilla license.

Check it out…
http://code.google.com/p/asadobewave/

It has been moved to here…
http://code.google.com/p/as3wavelib/