Monday, May 11, 2009

PureMVC vs Cairngorm framework comparison

Reasons to use PureMVC over Cairngorm.

#1 IMO if your gonna use Cairngorm your better off just going ahead and skipping every framework concept and just making classes with static (global) variables. That's what it feels like to me anyway lol.

#2 Makes it too easy for you to be sloppy. Accessing your model locator everywhere in your app can get ugly fast. PureMVC has a very structured but flexible way to code. Once you get comfortable with PureMVC, you will be able to get up to speed in other projects coded with PureMVC much quicker than Cairngorm coded projects.

#3 If your just starting to try to learn Cairngorm and find it confusing, it's cause you can't make sense of something that doesn't make sense!

#4 It's difficult to make a modular program in Cairngorm. Since the controller/models are singletons only one instance can exist (thus only one instance of the application). There are ways to get it to work, but you're gonna have to think outside the box for that..
PureMVC Multicore provides a framework for creating modular applications right out of the box.

#5 PureMVC utilities. The PureMVC community has added more capabilities on top of the PureMVC framework such as Undo/Redo (works great BTW), Pipes, etc.

#6 Scalability. It just gets way too messy trying to make a complex Cairngorm application. It can especially happen if you're just beginning at it or have been coding lazily. Because coding in PureMVC is much more structured, you won't be held back in the late game.

#7 PureMVC is fun to program in. Cairngorm is a nightmare :P

#8 Views can actually be reused in PureMVC. It's hard to do this in Cairngorm with all the views accessing directly to the global variables in the models. The reason PureMVC can decouple the view from the model is it has something called Mediators which take care of displaying and interaction in the views.

#9 Cairngorm is Adobe's official framework, and Adobe has been pissing me off lately with all the bugs I keep running into :P

p.s. Sorry for the long rant :P

Friday, May 1, 2009

HSlider as scrubber bar showing percent downloaded

If you are making a simple video component with VideoDisplay and want
to use the HSlider as the scrubber bar, you might run into the problem
of trying to display the % of the video that has been downloaded.

We can use HSlider's showHighlightTrack property for that. But
first we have to figure out how we can set it programmatically.

Heres how:


package com.flexas3.components
{
import mx.controls.HSlider;
import mx.core.Container;
import mx.core.IFlexDisplayObject;
import mx.core.mx_internal;
import mx.styles.ISimpleStyleClient;

use namespace mx_internal;
public class HSliderProgress extends HSlider
{
[Bindable]
private var _progress:Number = 0;
public function get progress():Number {
return _progress;
}
// 0-1
public function set progress(o:Number):void {
if (o < 0) o = 0;
if (o > 1) o = 1;
_progress = o;
}


/**
* @private
*/
override mx_internal function drawTrackHighlight():void
{
var track:IFlexDisplayObject = innerSlider.getChildAt(0) as IFlexDisplayObject;
var highlightTrack:IFlexDisplayObject = innerSlider.getChildAt(1) as IFlexDisplayObject;

if (track && highlightTrack)
{
var xPos:Number;
var tWidth:Number;

xPos = track.x;
// minus xPos is the right side offset
tWidth = track.width*progress;
//trace('track.width', track.width, 'tWidth', tWidth);
highlightTrack.move(xPos, track.y + 1);
highlightTrack.setActualSize(tWidth > 0 ? tWidth : 0, highlightTrack.height);
}
}

}
}


When you instantiate the HSliderProgress make sure to set
showHighlightTrack="true".

Also, as you get your video net_status updated just bind the
bytesLoaded/bytesTotal to the progress property.

Also one nice thing is that you can style it the way you'd normally style HSlider with Flex skinning.