Archive for the 'Flash' Category

Pixlr: An online PhotoShop

I just came across an excellent express alternative to PhotoShop that runs in the Flash Player, Pixlr!

I’m surprised to see how many of Photoshops features they have been able to implement in this fast loading clone. Great things such as filters and adjustments, magic wand selection, layers with blend modes, smudge, clone, pinch and bloat tools. The app even has a fullscreen mode :).

With the release of Flash 10 and Pixel Bender, I’m sure this app has a very bright future. Just please lose the Vista theme!

Check it out: pixlr.com/app

Flash 9 Player on PLAYSTATION3

So it now sounds like the cat is out of the bag. link

Yes, Flash 9 shall be shipping with PS3 Firmware 2.50.

Extra Notes:

  • No JIT support :(
  • Video playback is accelerated
  • Filters cause big slowdowns
  • Network access also dramatically effects performance
  • Guimark Result: Average fps is 4.5fps

    http://www.craftymind.com/factory/guimark/GUIMark_Flex3.html
  • BubbleMark Result: 20fps as default setting(16 balls)

    http://bubblemark.com/flex.htm

Flash on the Cloud: Lightning

With clients becoming thinner by the day and the desire to cut costs of CE devices, I’m wondering if OTOY type technology really is the future of experience viewing. For the uninitiated, OTOY enables extremely thin clients to explore rich 3D worlds via server side rendering. Below is a YouTube video of an OTOY demonstration. You could almost imagine the death of video game consoles via this type of technology in the years to come.

With this amazing proof of concept in the bag, I’m wondering if the same thing could be done to the Flash Platform.

Now, I’m not talking about the Flash Player simply just steaming OTOY content, I’m talking about actual SWF’s being rendered server-side and the result being streamed to a super thin Flash Player on the client end. Obviously this opens a huge amount of questions about cost, infrastructure, delivery, etc. But with the arrival of OTOY I know this can be done.

A “Lightning” system would allow for instant application upgrades, not just on the application level, but on the runtime level also. Custom installs of the system could allow operators to build in custom Player API’s to take advantage of hardware/needs on the cloud without worrying about the clients runtime compatibility. You would pick up some other free features such as simple P2P setup, etc.

With the Flash Player becoming heavier and more feature rich by the day. And the ever increasing demand for killer thin client solutions, it seems that a “Lightning” strike could be inevitable.

OTOY Demonstration:

Working with Shaders/Filters in Flash 10

Disclaimer: Beta API, APIs may change. Article based on investigatory work via code introspection.

Update: “Hydra” is now known as “Pixel Bender”

Loading Hydra Filters

The Flash API encapsulates Hydra Filters as a flash.display::Shader instances. To create a Shader instance we need to inject the byte code from a compiled Hydra filter file into it. We can do this in two familiar ways.

1) Using ActionScript 3 meta tags to inject the byte code directly into our compiled SWF.

[Embed(source="HydraFilter.hbc", mimeType="application/octet-stream")]
var Filter:Class;

var shader:Shader = new Shader(new Filter());

2) With the use of the URLLoader class which brings all the benefits of runtime loading.

function loadFilter() {
        loader = new URLLoader();
        loader.dataFormat = URLLoaderDataFormat.BINARY;
        loader.addEventListener(Event.COMPLETE, loadCompleteHandler);
        loader.load(new URLRequest("HydraFilter.hbc"));
}

function loadCompleteHandler(event:Event):void {
        var shader:Shader = new Shader(loader.data);
}

Accessing Filter Properties and Defining Input

Hydra filters usually take different parameters in order to control their output. For example, the existing BlurFilter in Flash has blurX and blurY to control the strength of its “blurring”. Flash 10 encapsulates a single filter parameter into a dynamic flash.display::ShaderParameter class instance. This class is dynamic in order for it to be able to inspect custom parameter meta-data . For example you might have minValue / maxValue set on the filter parameter (see below).

parameter float strength
 <
     description: "The strength of the blur";
     minValue: 0.0;
     maxValue: 50.0;
 >;

To set the value of a ShaderParameter, you can access the ‘value’ property of ShaderParameter and get/set Arrays on it. The size and type of data in the array all depends on the type of data the filter parameter is expecting. You can ask the ShaderParameter which flavor of Array it’s expecting by calling the ‘type’ property of ShaderParameter. In our Hydra code above you can see that the parameter is a float. A float requires a single Array element with the data type of that element being a Number. So for example, we could set … value = [10] .. and now the value of the strength is 10.

All of these ShaderParameter’s are wrapped up in another shader centric class called flash.display::ShaderData. This class is completely dynamic and gives access to ShaderParameter’s by their name. You should also be able to enumerate over them using a “for each” or “for in” loop. ShaderData also gives you assess to meta-data from the header of the Hydra filter such as its name, version, etc. So extending on the previous example, we can now say .. shaderData.strength.value = [10]

ShaderData also exposes the image input properties of a Hydra filter. For example our Hydra filter may be expecting a bitmap with an alpha channel …

input image4 src;

We represent this bitmap data input with yet another shader centric dynamic class called flash.display::ShaderInput. This class exposes some key meta-data type information about the input image property such as how many channels the bitmap should process (shaderInput.channels:int) and the index order of the property within the filter (shaderInput.index:int). The main property of this class is the ‘input’ property. Here we can set either a BitmapData, ByteArray or a Vector.<Number> instance that contains our input image. If the input is not a BitmapData type, then ‘width’ and ‘height’ properties must also be assigned to the ShaderInput instance.

Below is an example of assigning BitmapData to a ShaderInput (input image4 src) through our ShaderData:

shaderData.src.input = new BitmapData(123, 321, true, 0xFFCC00CC);

ActionScript developers should not typically need to create ShaderParameter and ShaderInput instances. All instances are created automatically to map to the requirements of the custom Hydra filter. All of these data instances should be accessible via the flash.display::Shader instance that we created before from our Hydra filter byte code. The property of Shader that gives us access to all of these parameters, inputs and meta-data is the ‘data’ property.

Example:

var shader:Shader = new Shader(hydraShaderByteCode);

trace(shader.data.name) // "DemoFilter"
trace(shader.data.version) // "1"
trace(shader.data.strength.maxValue) // 50.0
trace(shader.data.strength.description) // "The strength of the blur"
trace(shader.data.src.channels) // 4

shader.data.strength.value = [10]
shader.data.src.input =  new BitmapData(123, 321, true, 0xFFCC00CC);

Filter Rendering - BitmapFilter

Once you have encapsulated your hydra filter as a Shader, everything else starts to become very familiar. We just have one more element to add. The missing element is the flash.filters::ShaderFilter class. This class extends flash.filters::BitmapFilter, which is the base class for all existing DisplayObject filters. And so, we can now utilize our Shaders in exact same way that we would traditionally work with existing built in filters such as BlurFilter.

NOTE: BitmapFilter will automatically set the first ShaderInput for you. The DisplayObject that the BitmapFilter is assigned to becomes the first image input. Additional image inputs shall need to be defined in the usual way.

In this example below, we can how we wrap the Shader up into a ShaderFilter and apply it to a Sprite.

[Embed(source="HydraFilter.hbc", mimeType="application/octet-stream")]
var MyFilter:Class;

var shader:Shader = new Shader(hydraShaderByteCode);
var filter:ShaderFilter = new new ShaderFilter(shader);
filter.data.strength.value = [10];

var sprite:Sprite = new Sprite();
sprite.graphics.beginFill(0xcc00cc);
sprite.graphics.drawRect(0,0,123,321);
sprite.filters = [filter];

addChild(sprite);

Filter Rendering - Threaded Background Jobs

Sometimes a Hydra filter might take longer than desired to render. And because Flash currently runs on a single threaded rendering loop, a taxing filter could leave an applications UI unresponsive for an undesired amount of time. To avoid this scenario, Adobe have added the ability to perform background GPU filter rendering outside of the main thread, in the form of “jobs”.

The Flash API defines the flash.display::ShaderJob class for developers to manage this background rendering process. Here is an example using a BitmapData object as our output “bucket”.

function startJob(shader:Shader, target:BitmapData) {
        var job:ShaderJob = ShaderJob(shader, target);
        job.addEventListener(ShaderEvent.COMPLETE, shaderJobCompleteHandler)
        job.start()
}

function shaderJobCompleteHandler(e:ShaderEvent):void {
        var  result:BitmapData = e.bitmapData;
}

new Vector - ActionScript 3’s Typed Array

Flash Player 10 introduces a new core data type to store lists of data called “Vector”. It’s almost identical to the vanilla ActionScript array we use today but with the added benefit of being strictly/strongly typed. Strict typing is very beneficial, it helps create error free code while coding and compiling, allows for understandable APIs and best of all, increases code execution performance.

Vector is a top-level class just as Array is so you will not need to import it.

Below is an example of creating a Vector for the int type.

 var vec:Vector.<int> = new Vector.<int>();

Notice that we define the type of Vector with the use of the less-than/lower-than brackets.

Here is an extended example using a Vector for holding Sprites.

class Foo  {

	private var _displayChildren:Vector.<Sprite>;

	function Foo() {
		_displayChildren = new Vector.<Sprite>;
	}

	public function addChild(child:Sprite):void {
		_displayChildren.push(child);
	}

	public function removeChild(child:Sprite):void {
		var idx:int = _displayChildren.indexOf(child);
		_displayChildren.splice(idx,1);
	}

	public function get numChildren():uint {
		return _displayChildren.length;
	}

}

If you attempt to add data of the wrong type to a vector, you shall receive a “Type Coercion failed: cannot convert” error. There is however some exceptions, for example if you have a int typed Vector and you try to add a String to it using a push or unshift method, it shall perform an int(string) conversion.

intVec.push("00123")
intVec.push("hello")
trace(intVec) // 123, 0

If you try this however .. intVec[0] = “00123″ .. it shall result in a “Implicit coercion of a value of type String to an unrelated type int” error.

The only method Vector didn’t pick up from its Array cousin is sortOn. Apart from that, every method from Array is available to use to manipulate Vector.

Vector does introduce something new though, the ability to force a fixed collection length. Below is an example on how to enable fixed length.

// int Vector with fixed length of 5
var vec:Vector.<int> = new Vector.<int>(5, true);
trace(vec.fixed) // true
trace(vec) // 0, 0, 0, 0, 0

While in fixed mode, the methods push/pop/shift/unshift/splice/..etc shall not work and shall result in a “Cannot change the length of a fixed Vector.” error.

If you go out of the fixed range using the square bracket notation .. vec[15] = 1 .. you shall find this error “The index 15 is out of range 5.”.

Enable GPU Composing on Flash Player 10 Content

By default, hardware accelerated composing is turned off in the current Flash Player 10 beta, and rightly so. You should only need to use GPU composing if your application really benefits from it.

If you want to enable this new feature in the new beta player, the only way to currently do this is via an attribute in your HTML/JS embed code. The attribute in question is not an addition, it is the familiar “wmode” parameter. The parameter traditionally defines how Flash content is “windowed” on a page with the current choices being “window“, “opaque” and “transparent“. With Flash Player 10, the number of choices gets bumped up to five with the addition of “direct” and “gpu“.

wmode=”direct”

“Direct” instructs the player to totally bypass the parent web browser for rendering. You might compare it to standalone players performance with the little more kick.

wmode=”gpu”

“GPU” is full hardware accelerated composing. But note, GPU mode is not a magic bullet for speeding up everything, in some scenarios it may in-fact course performance drains.

Create Flash Player 10 Beta Content

As announced in the early hours of this morning, Flash Player 10 Beta is now available to the general public via the labs.adobe.com website. This is fantastic news, but almost useless at the same time if your unable to create content for it.

Well never fear, the Adobe opensource team has release documentation on the steps you need to take in order to create your first Flash 10 content!

Check it out: opensource.adobe.com

Flash Player 10 Beta Released To The Public

Today, Adobe have released their first public beta of Flash Player 10 on their labs website. Code named “Astro”, Flash Player 10 introduces a whole fist full of compelling new features. It’s headline feature being a new range GPU utilization’s; from accelerated compositing to custom filter rendering. 3D is also introduced and bumped up to a first classes citizen with the introduction of the Z axis to all display object. On the coding side, we see the welcomed introduction of typed arrays which mean iterating over data just go a whole lot faster. Add in a new text layout engine and we’re only just touching the surface!

Player 10 is indeed an sneak peak into the future of Flash. If they can do this much with just one version release, just imagine what is going to happen in 11 and 12. Dynamic VM scripting languages FTW! :)

Why are you still reading this? Check it out: labs.adobe.com

Best Flash 3D I’ve Seen to Date: Alternativa3D

Paul Tondeur has posted an article about the new Milestone 1 of the Alternativa3D Flash engine.

The new showcase demo for Milestone 1 looks insanely great! I like the use of Stage quality/poly-count toggling. The sound mixing is nice, especially with headphones. And also, take the time to press the “T” key to view the polygon outlines, they look to be very dynamic; not much seems to be going on “off screen”.

Check it out for yourself:

alternativa3d_bunker.jpg

Flash on iPhone & Flash 10 Thoughts

This week I’ve been reading a lot of posts from people complaining about the lack of Flash support for the iPhone. A lot of this commentary has risen from Steve Jobs himself having said that “it performs too slowly on the iPhone“. Now, I don’t doubt his reasoning for a second, but I’m not saying that AVC2 isn’t blazing fast. I’m saying that a lot of SWF on the Internet are poorly constructed, resulting in CPU bombardment.

The cost of a cycle on a handheld CE device is great because sooner or later you’re going to run out of power. If you’re running poorly constructed SWFs all day long from random-bogus-flash-site.com then your either going to run our of power fast or leak memory everywhere.

Today I could be viewing a small flash banner ad from website X that will motor up my laptops fans with what appears to be next to no functionally or animation - what the hell!? I propose that someone please start a Flash name & shame website that decompiles these SWFs so that common mistakes can filter down to the people who created them.

I believe that poorly constructed SWFs are the main reason why you won’t be seeing Flash on the iPhone anytime soon. Steve wants a consistent Safari experience for it’s users. It would be too painful if Safari crashed every couple of minutes because ‘Banner ad company XYZ’ hired the lowest bidder.

And of course it would only be naive to say that Flash on the iPhone isn’t a clash of interests. Why would Apple want another media player on the iPhone? Remember that at the end of the day, the iPhone is still the flagship iPod. Apple won’t sell any iTunes media if you can stream it for free all day long.

Of course Apple could choose to disable Flash in Safari, but allow you to create springboard apps. But this is really what the iPhone SDK is all about, so I don’t really think Flash fits here. Maybe platform portability is the best argument to have Flash apps, but why would Apple go for that. For starters, Apple doesn’t want famous iPhone app “Q” to one day start running on a Sony Ericsson phone. How would that sell iPhones?

The iPhone is extremely powerful in terms of multimedia rendering, You’re able to utilize its engaging Core Animation framework featuring embedded OpenGL to create the kinds of real time effect you would see in ‘Photo Booth’ for example. The ability to draw power from hardware acceleration means that the iPhone can pushing bits around the screen at a very decent frame-rate without bothering the CPU too much.

Could Flash 10 with hardware acceleration be the answer to the iPhone SDK? It seems today that AVM2 can push code around with ease but its display list rendering is greatly lacking. Could Flash 10 solved this? Could 10 be the platform of choice for competing mobile brands? It seems to me that portable mobile apps are the best way to compete with the iPhone right now. So, wouldn’t it be great if those portable apps were F10 SWFs?!

Next Page »