Skip to content

Instantly share code, notes, and snippets.

@johnyanarella
Created February 11, 2011 13:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save johnyanarella/822347 to your computer and use it in GitHub Desktop.
Save johnyanarella/822347 to your computer and use it in GitHub Desktop.
Example of flex-extensions InvalidationTracker. See: https://github.com/johnyanarella/flex-extensions/
package
{
import com.codecatalyst.util.invalidation.InvalidationTracker;
import mx.core.UIComponent;
public class InvalidationTrackerExampleComponent extends UIComponent
{
// ========================================
// Protected properties
// ========================================
/**
* Invalidation tracker.
*/
protected var tracker:InvalidationTracker = null;
// ========================================
// Public methods
// ========================================
[Invalidate("properties")]
[Bindable]
/**
* First property.
*/
public var first:String;
[Invalidate("displaylist,properties,size")]
[Bindable]
/**
* First property.
*/
public var second:String;
// ========================================
// Constructor
// ========================================
/**
* Constructor.
*/
public function TestComponent()
{
super();
tracker = new InvalidationTracker( this );
}
// ========================================
// Protected methods
// ========================================
/**
* @inheritDoc
*/
override protected function measure():void
{
super.measure();
if ( tracker.invalidated( "second" ) )
{
trace( "Second invalidated." );
}
}
/**
* @inheritDoc
*/
override protected function commitProperties():void
{
super.commitProperties();
if ( tracker.invalidated( "first" ) )
{
trace( "First invalidated - previous value: " + tracker.previousValue( "first" ) + " current value: " + first );
}
if ( tracker.invalidated( "second" ) )
{
trace( "Second invalidated - previous value: " + tracker.previousValue( "second" ) + " current value: " + second );
}
if ( tracker.invalidated() )
{
trace( "A tracked property was invalidated." );
}
// No longer required - InvalidationTracker will automatically reset() invalidated properties in response to FlexEvent.UPDATE_COMPLETE.
// tracker.reset( "first" );
}
/**
* @inheritDoc
*/
override protected function updateDisplayList( unscaledWidth:Number, unscaledHeight:Number ):void
{
super.updateDisplayList( unscaledWidth, unscaledHeight );
if ( tracker.invalidated( "second" ) )
{
trace( "Second invalidated." );
}
// No longer required - InvalidationTracker will automatically reset() invalidated properties in response to FlexEvent.UPDATE_COMPLETE.
// tracker.reset( "second" );
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment