Created
February 11, 2011 13:40
-
-
Save johnyanarella/822347 to your computer and use it in GitHub Desktop.
Example of flex-extensions InvalidationTracker. See: https://github.com/johnyanarella/flex-extensions/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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