 
     /**
      *  Constructor.
-     */	
-	public function CSSPropertyInjector()
-	{
-		super();
-	}
-	
+     */    
+    public function CSSPropertyInjector()
+    {
+        super();
+    }
+    
 
     //--------------------------------------------------------------------------
     //

import mx.styles.StyleManager;

/**
 *  An utility to dynmacially inject values from CSSStyleDeclarations into a target 
 *  object.
 * 
 *  NOTE: This code is being developed and has not be thoroughly tested... 

    /**
     *  Added to adhere to the framework lifecycle naming convention. Just calls 
     *  commitProperties().
     */    
    public function invalidateProperties() : void
    {
        commitProperties();
    }
    
    /**
     *  @protected
     * 
     *  Applies the injection when all the required properties have been committed. 
     */
    protected function commitProperties() : void
    {
        //  if at least target or targets is set as well as styleName
        //  and styles.. and one of these values has changed... 
        //  the style declaration is retreived and applied
        if ( ( __target != null || __targets != null ) && 
             ( __styles != null || useIntrospection == true ) &&
             __styleName != null &&  
             ( __targetChanged == true || __targetsChanged == true ||
               __styleNameChanged == true || __stylesChanged == true ) )
        {
            if ( __styleNameChanged == true )
            {
                getCSSStyleDeclaration();
            }
            
            __targetChanged = __targetsChanged = __styleNameChanged = __stylesChanged = false;
            
            applyStyles();
        }
    }
    
    /**
     *  @protected
     * 
     *  Loads the CSSStyleDeclaration from the StyleManager.
     */
    protected function getCSSStyleDeclaration() : void
    {
        __cssStyleDeclaration = StyleManager.getStyleDeclaration( styleName );
        
        if ( __cssStyleDeclaration == null )
        {
            __cssStyleDeclaration = StyleManager.getStyleDeclaration( "." + styleName );
        }
    }
    
    /**
     *  @protected
     *  
     *  Applies the style values in __cssStyleDeclaration to the target object(s)
     */
    protected function applyStyles() : void
    {
        var styles : Array = this.styles;
        
        if ( useIntrospection == true )
        {
            var description : XML = describeType( target );
            var propNames : Array = [];
            for each ( var accessor : XML in description.accessor )
            {
                propNames.push( accessor.@name.toString() );
            }
            for each ( var variable : XML in description.variable )
            {
                propNames.push( variable.@name.toString() );
            }
            styles = propNames;
        }
        
        if ( target != null )
        {
            assignStylesToTarget( styles, this.target );
        }
        
        if ( targets != null )
        {
            for each ( var target : Object in targets )
            {
                assignStylesToTarget( styles, target );
            }
        }
    }
    
    /**
     *  @protected
     * 
     *  Assigns a set of styles to a target object
     */
    protected function assignStylesToTarget( styles : Array, target : Object ) : void
    {
        for each ( var style : String in styles )
        {
            if ( target.hasOwnProperty( style ) && 
                 __cssStyleDeclaration.getStyle( style ) != null )
            {
                target[ style ] = __cssStyleDeclaration.getStyle( style );
            }
        }
    }
    
    
    //--------------------------------------------------------------------------
    //
    //  Variables
    //
    //--------------------------------------------------------------------------

    protected var __target : Object = null;
    protected var __targetChanged : Boolean = false;
    
    protected var __targets : Array = null;
    protected var __targetsChanged : Boolean = false;
    
    protected var __styleName : String = null;
    protected var __styleNameChanged : Boolean = false;
    
    protected var __styles : Array = null;
    protected var __stylesChanged : Boolean = false;
    
    protected var __useIntrospection : Boolean = true;
    protected var __useIntrospectionChanged : Boolean = false;
    
    protected var __cssStyleDeclaration : CSSStyleDeclaration = null;
    
} //  end class
} //  end package

