Looks good I’ll take a look, and see if I can't get some ideas working. I'm
certainly willing to share Mike that’s really no problem. I just think that
being able to re-brand a app with out recompile would be so handy especially
to me, and most likely many others. But to be able to do it with out going
through every control and using the built in setStyle would be the cherry on
the cake.

Jason


-----Message d'origine-----
De : flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] la
part de Michael Schmalle
Envoyé : lundi 5 juin 2006 17:00
À : flexcoders@yahoogroups.com
Objet : Re: [flexcoders] Runtime CSS Styles Flex 2.0 B3


ok,

Well, there is two properties now in the framework, inheritingStyles and
nonInheritingStyles. I didn't have these things to work with in the v2
framework. From testing about a month ago when this question came up, I
realized alots of possiblities using these objects.

Not to mention the whole way styles cascade and are registered are completly
different.

The way I see it;

I didn't even notice but there is no load() on the StyleSheet object
anymore.

What I did with my runtime in AS2 was created an ExternalStyleSheet class.
Then I created an ExternalStyleCache class that was a singleton.

Well, I will just post the two classes. If anybody uses any of this, please
just run me a note becasue I would like to make it to, just not enough time
to do it all.

Mind you, this was from AS2 v2 components and it DID work great. I am just
posting this becasue I actually think a pattern like this might actually
work. I havn't had enough time to actually figure out if it will work in
FLex 2.

And.. there is no applyStyles() in this, that was in my extended framework.

Peace, Mike

ExternalStyleCache ::
------------------------------------------------------------------------

import mx.events.EventDispatcher;
import com.teotigraphix.styles.external.ExternalStyleSheet;

/*

var cache = ExternalStyleCache.getStyleCache();

    - If the static _styleCache is not created
    - _styleCache = new ExternalStyleCache
        - _global.styleCache = this
        - getDataProvider()
            - __dataProvider = new Array()
        - EventDispatcher.initialize(this);




*/







/**
 * This is used with all ObjectUI classes to track externally loaded and
internally loaded style sheets.
 * <p>Adds creation, loading and removing methods to the styleCache API.</p>
 * @author Michael J. Schmalle
 * @email [EMAIL PROTECTED]
 * @date 01-11-05
 * @version 0.9.0
 * @updated 01-12-05 MS [0.1.1] Commenting, got this class to work on
"proto" level.
 * @updated 02-23-05 MS [0.2.0] MAJOR refactoring, new file and new
algorithm for accessing styles.
 * @updated 03-07-05 MS [0.3.0] Created new file in hopes to get good
abstraction and encapsulation going.
 * @updated 03-16-05 MS [0.9.0] I like this version, commented and pruned
all methods. Looks good now!
 * @updated 08-23-05 MS [0.9.1] Working to encapsulate this into a compiled
SWF component.
 */
class com.teotigraphix.styles.external.ExternalStyleCache
{
    // mixed in from event dispatcher
    public var dispatchEvent:Function;
    public var removeEventListener:Function;
    public var addEventListener:Function;
    var EVT:Function = mx.utils.Delegate.create;

    /**
    The instance class name of this class.
    */
    var className:String = "ExternalStyleCache";

    /**
     * The reference to or single instance of the ExternalStyleCache
     */
    private static var _styleCache:ExternalStyleCache = null;

    /**
     * The single object of external .css files.
     */
    private var __dataProvider:Object;

    /**
     * The private constructor, we also initialize some other stuff.
     * <p>The EventDispatcher and a lazy reference to this singleton class
in the _global.styleCache property.</p>
     */
    private function ExternalStyleCache()
    {
        if (_global.styleCache == undefined) {
            _global.styleCache = this;
            getDataProvider();
            EventDispatcher.initialize(this);
        }
    }

    /**
     * Returns the only access point into this class.
     * Create the _styleCache private static property, call getDataProvider
() which initializes the __dataProvider
     * array for all the ExternalStyleSheet instances to be hung.
     * @return the singleton ExternalStyleCache instance.
     * @usage var styleCache = ExternalStyleCache.getStyleCache ();
     */
    public static function getStyleCache():ExternalStyleCache
    {
        if (_styleCache == null) {
            _styleCache = new ExternalStyleCache();
        }
        return _styleCache;
    }

    /**
     * Returns the cache's dataProvider array, which why would I want this
public?
     * @return the cache's dataProvider array.
     */
    private static function getDataProvider():Array
    {
        var cache = getStyleCache();
        if (cache.__dataProvider == undefined) {
            cache.__dataProvider = new Object(); //new Array();
        }
        return cache.__dataProvider;
    }

    /**
     * Returns the ExternalStyleSheet instance named sheetName.
     * @param sheetName a string indicating the name of the
ExternalStyleSheet instance to be returned.
     * @return the ExternalStyleSheet instance named sheetName otherwise if
not found returns false.
     */
    function getStyleSheet(sheetName:String):ExternalStyleSheet
    {
        var dp = getDataProvider();
        if (dp[sheetName] != undefined) {
            return dp[sheetName];
        }
    }

    /**
     * Creates an new instance of the ExternalStyleSheet and returns it.
     * This method also adds the styleSheet to the __dataProvider array.
     * @param sheetName a string indicating the name of the new
ExternalStyleSheet instance.
     * @param sheetObj a ExternalStyleSheet instance, this does not have to
be set, if not set the method
     * creates a new ExternalStyleSheet instance.
     * @return a newExternalStyleSheet instance, or the sheetObj after
inserting into __dataProvider array.
     */
    function createStyleSheet(sheetName:String, sheetObj,
overwrite:Boolean):ExternalStyleSheet
    {
        var dp = getDataProvider();
        //trace ("createStyleSheet () " + sheetName)
        if (dp[sheetName] != undefined && overwrite == undefined) {
            return dp[sheetName];
        }

        if (sheetObj == undefined) {
            sheetObj = new ExternalStyleSheet();
        }
        sheetObj.setName(sheetName);

        dp[sheetName] = sheetObj;

        return dp[sheetName];
    }

    /**
     * Removes a styleSheet from the __dataProvider array.
     * @param sheetName a string indicating the instance name of the
ExternalStyleSheet instance to remove.
     * @return Returns a boolean if removal was a success IE the sheet was
found and deleted.
     */
    function removeStyleSheet(sheetName:String):Boolean
    {
        var dp = getDataProvider ();
        if (dp[sheetName] != undefined) {
            delete dp[sheetName];
            return true;
        }
        return false;
    }

    /**
     * Loads and external .css file into a new ExternalStyleSheet instance.
     * @param sheetName a string indicating the instance name of the new
ExternalStyleSheet instance.
     * @param sheetURL a string indicating the css url to load the .css
sheet from.
     * @param scope an object reference to the scope of the handler call.
     * @param func a function reference to the load handler after load
complete.
     * @param overwrite a boolean indicating if an existing
ExternalStyleSheet with the same name should be overwritten.
     * @return the new ExternalStyleSheet instance, remember this is not
loaded yet, just the reference.
     */
    function loadStyleSheet(sheetName:String, sheetURL:String, scope,
func:Function, overwrite:Boolean):ExternalStyleSheet
    {
        var styleSheet = createStyleSheet(sheetName, undefined, true);

        var loadDelegate = EVT(scope, func);

        styleSheet.addEventListener("onLoad", loadDelegate);
        // there is a way to enter the url in the constructor to
        styleSheet.load(sheetURL);

        return styleSheet;
    }

    /**
     * Checks to see if the sheetName string exists in the __dataProvider
array.
     * @param sheetName a string indicating the instance name of the
ExternalStyleSheet instance to check against.
     * @return a boolean true if the name exists, false it the name does not
exist.
     */
    function exists(sheetName:String):Boolean
    {
        var dp = getDataProvider();

        for (var name in dp) {
            if (name == sheetName) {
                return true;
            }
        }
        return false;
    }

    function toString():String
    {
        return "[ExternalStyleCache]";
    }
}




ExternalStyleSheet
----------------------------------------------------------------------------
----

import mx.events.EventDispatcher;
import com.teotigraphix.managers.UIStyleManager;
import mx.styles.StyleManager;
import com.teotigraphix.utils.TEOUtility;




/**
 * This is an object holder class for the ExternalStyleCache class.
 * @author Michael J. Schmalle
 * @email [EMAIL PROTECTED]
 * @date 01-11-05
 * @version 0.9.0
 * @updated 03-16-05 MS [0.9.0] Refactored, commented and is ready for use!
 * @updated 08-23-05 MS [0.9.1] Working to encapsulate this into a compiled
SWF component.
 */
class com.teotigraphix.styles.external.ExternalStyleSheet
{
    var className:String = "ExternalStyleSheet";

    // mixed in from event dispatcher
    var dispatchEvent:Function;
    var removeEventListener:Function;
    var addEventListener:Function;
    var EVT:Function = mx.utils.Delegate.create; // alias to Delegate create

    private var __description:String; // used to hold the description that
is printed in the dumpFile () method.
    private var __name:String;    // used to keep track of this instance in
the ExternalStyleCache
    private var __sheetURL:String; // used to hold the external .css url for
this instance
    private var __styleSheet:TextField.StyleSheet; // used for loading
external .css files
    private var __xmlObject:XML; // used from loading external .xml files

    private var objects:Object; // the internal object holding all the sub
styleObjects
    var cssObjects = new Object();

    public static var xmlExtensionName:String = "xml";
    public static var cssExtensionName:String = "css";

    // Our map from TextFormat to CSS
    static var CSSMap:Object =
    {
        font:"fontFamily",
        size:"fontSize",
        color:"color",
        leftMargin:"marginLeft",
        rightMargin:"marginRight",
        italic:"fontStyle",
        bold:"fontWeight",
        align:"textAlign",
        indent:"textIndent",
        underline:"textDecoration",
        embedFonts:"embedFonts"
    }

    public function set description(description:String)
    {
        __description = description;
    }
    public function get description():String
    {
        return __description;
    }

    /**
     * Sets the instance name for this instance.
     * @param name a string indicating the instance name for this instance.
     */
    public function setName(name:String):Void
    {
        __name = name;
    }

    /**
     * Gets the instance name for this instance.
     * @return a string indicating the instance name for this instance.
     */
    public function getName():String
    {
        return __name;
    }

    /**
     * Sets this instances external .css url (if loading externally).
     * @param url a string indicating the instance url.
     */
    public function setURL(url:String):Void
    {
        __sheetURL = url;
    }

    /**
     * Gets this instances external .css url that it was loaded with (if
loaded externally).
     * @return a string url for this instance.
     */
    public function getURL():String
    {
        return __sheetURL;
    }

    /**
     * Returns an array of the styleObject's styleName held in this sheet.
     * @return an array hold the string styleNames of all the styleObjects
in this sheet.
     */
    public function getStyleNames():Array
    {
        var names:Array = new Array();

        for (var name in cssObjects /*objects*/) {
            names.push(name);
        }

        return names;
    }

    /**
     * Constructor, initialize url, styleSheet and objects array, also
initialize events for this object.
     */
    public function ExternalStyleSheet(sheetURL:String)
    {
        if (sheetURL != undefined) {
            __sheetURL = sheetURL;
        }

        __styleSheet = new TextField.StyleSheet();
        __xmlObject = new XML();
        __xmlObject.ignoreWhite = true;

        // this needs to be implemented now
        objects = new Object();
        cssObjects = new Object();

        EventDispatcher.initialize(this);
    }

    /**
     * Calls load () on the TextField.StyleSheet object.
     * @param sheetURL a string indicating the url to load the external .css
file from. If this param is undefined,
     * the internal css url is used.
     */
    public function load(sheetURL:String):Void
    {
        var o = this;
        if (sheetURL != undefined) {
            __sheetURL = sheetURL;
        }

        // Lets get the type!! xml or css
        var isXML = ((__sheetURL.indexOf("." + xmlExtensionName, 0)) != -1)
        var isCSS = ((__sheetURL.indexOf("." + cssExtensionName, 0)) != -1)

        var loadDelegate =  EVT(this, onLoad);

        if (isCSS) {
            __styleSheet.onLoad = loadDelegate;
            __styleSheet.load(__sheetURL)
        }

        if (isXML) {
            __xmlObject.onLoad = loadDelegate;
            __xmlObject.load(__sheetURL);
        }
    }

    /**
     * The onLoad hadler for the TextField.StyleSheet object.
     * This method handler delgates then to the user specific handler by
dispatching an onLoad event.
     * @param success a boolean indicating wether there was a success
loading the external .css file.
     */
    function onLoad(success:Boolean):Void
    {
        var isXML = ((__sheetURL.indexOf("." + xmlExtensionName, 0)) != -1)
        var isCSS = ((__sheetURL.indexOf("." + cssExtensionName, 0)) != -1)

        // need to create an objects array that holds all the style classes
from the loaded style sheet.!!!
        if (isCSS) {
            createObjectsFromCSS();
        }
        if (isXML) {
            createObjectsFromXML();
        }

        dispatchEvent({type:"onLoad", styleSheet:this})
    }

    /** STILL CHECKING OUT TODO!!!
     * This will merege the style object name with the new sd object
     * this dosn't happen when the style sheet loads, it happens when an
instances styleObject is set to
     * a style object on this page, then the
     */
    function mergeCurStyleSheetProperties():Void
    {
        var styleNames = __styleSheet.getStyleNames();

        for (var i = 0; i < styleNames.length; i++) {
            var styleName:String = styleNames[i];
            var styleObject:Object = __styleSheet.getStyle(styleName);

            for (var propName in styleObject) {
                var propValue = styleObject[propName];
                //textList.push ("\t" + TEOUtility.convertToCSSName
(propName) + ":" + propValue + ";");
            }

        }
    }


    // this is mixing GOOD!
    private function createObjectsFromXML():Void
    {
        var xml = __xmlObject;

        //trace ("createObjectsFromXML ()  " + xml.firstChild)

        var numObjects = xml.firstChild.childNodes.length;
        var styleObjects:Array = xml.firstChild.childNodes;

        for (var i = 0; i < numObjects; i++) {
            var styleName:String = styleObjects[i].nodeName;

            //trace ("styleName = " + styleName)

            var styleObject:Object = styleObjects[i].attributes;

            //-------------------------------+
            objects[styleName] = new Object();
            //-------------------------------+

            for (var propName in styleObject) {
                var propValue = styleObject[propName];
                trace (propName + " == " + styleObject[propName])
                objects[styleName][propName] = propValue;
            }
        }

        convertXMLObjects();

        addObjectsToGlobalStyles();
    }



    /**
     * When an xml file is loaded, it is first parsed into the objects list.
      1 The objects object keys are the styleObject.styleName
      2 We loop through the styleObjects
      3 Loop through all properties of the styleObject
      4 Convert each property to it's proper type.
      5 Assign the new typed property back into the styleObject
      6 Now, the objects object hold typed properties
     */
    function convertXMLObjects():Void
    {
        //trace ("convertXMLObjects ()")
        var len = objects.length;
        for (var objectName in objects) {

            var curStyleObject = objects[objectName];
            //trace ("curStyleObject " + curStyleObject)

            for (var styleName in curStyleObject) {
                var value = curStyleObject[styleName];
                // !!!!!!! var newValue =
UIStyleManager.convertToStyleType(styleName, value);
                var newValue
                curStyleObject[styleName] = newValue;

                //trace ("Value = " + newValue + "  Type = " + typeof
(newValue))
            }
        }
    }

    /**
     * We call the TeoUtility.createStyleSheet () method, which is a factory
method for creating
     * Flash CSSStyleDeclaration objects and adds them to the _global.styles
object.
     1 Loop through all the styleObjects that have properly typed
properties.
     2 Create a new CSSStyleDeclaration object using the current styleObject
key for the newObj.styleName.
     then add it to the _global.styles object
     3 set the styleName
     4 loop through all the properties of the typed object adding them to
the CSS object
     5 save the new current CSS object onto the cssObject object.
     6 now there is a exact reference to the cssObjects objects in the
_global.styles.
     Any time we now say getStyleObject, we need to point that to the
cssObjects object.
     */
    function addObjectsToGlobalStyles():Void
    {
        // !!!!!!!! cssObjects =
com.teotigraphix.utils.TeoUtility.createStyleSheet(objects, cssObjects);
    }


    // this is mixing GOOD!
    private function createObjectsFromCSS():Void
    {
        trace("createObjectsFromCSS()")
        // get all the style names in the loaded sheet
        var styleNames = __styleSheet.getStyleNames();
        // loop through all the objects
        for (var i = 0; i < styleNames.length; i++) {
            var styleName:String = styleNames[i];
            var styleObject:Object = __styleSheet.getStyle(styleName);
            trace("styleName == " + styleName)
            trace("styleObject == " + styleObject)
            //-------------------------------+
            //objects[styleName] = new Object();
            cssObjects[styleName] = new Object();
            //objects[styleName].isLoaderObj = true;
            //-------------------------------+
            trace("===============")
            for (var propName in styleObject) {
                var propValue = styleObject[propName];
                //objects[styleName][propName] = propValue;
                cssObjects[styleName][propName] = propValue;
                trace(propValue + " == " + propName)
            }
        }
    }


    /**
     * Adds a style CSSStyleDeclaration object in to the cssObjects array.
     * @param styleName a string OR styleObject which contains a styleName
property.
     * @param styleObj a styleObject containing a styleName property.
     */
    function addStyleObject(styleName, styleObj):Void
    {
        var name:String;
        var obj:Object;

        if (typeof (styleName) == 'object') {
            name = styleName.styleName;
            obj = styleName;
        } else {
            name = styleName;
            obj = styleObj;
        }

        if (name != undefined && obj != undefined) {
            /*objects*/cssObjects[name] = obj;
        }
    }

    /**
     * Removes the styleObject with the name styleName from the objects
array.
     * @param styleName a string indicating the styleObject to remove.
     * @return A boolean indicating if the object removal was successful.
     */
    function removeStyleObject(styleName:String):Boolean
    {
        // this is wrong, we need a for( in ) loop

        for (var i = 0; i < objects.length; i++) {
            var curObj = cssObjects/*objects*/[i];
            var curName = curObj.styleName;
            if (curName == styleName) {
                objects.splice (i, 1);
                return true;
            }
        }
        return false;
    }

    /**
     * Returns the styleObject with the name of styleName.
     * @param styleName a string indicating the name of the styleObject to
return.
     * @return A styleObject with the name of styleName.
     */
    function getStyleObject(styleName:String)
    {
        return cssObjects[styleName];
    }


    /**
     * Dumps a valid css file into the output window.
     * @param traceFile a boolean indicating if the file is traced in the
output window(true) or is returned as a string(false).
     * @param lineBreak a string indicating the type of line break to put in
the return string.
     * @return A string representation of this css sheet(if traceFile param
is false).
     */
    function dumpFile(traceFile:Boolean, lineBreak:String)
    {
        var isXML = ((__sheetURL.indexOf("." + xmlExtensionName, 0)) != -1)
        var isCSS = ((__sheetURL.indexOf("." + cssExtensionName, 0)) != -1)

        // need to create an objects array that holds all the style classes
from the loaded style sheet.!!!
        if (isCSS) {
            dumpCSSFile(traceFile, lineBreak);
        }
        if (isXML){
            dumpXMLFile(traceFile, lineBreak);
        }
    }

    /**
     * Dumps a valid css file into the output window.
     * @param traceFile a boolean indicating if the file is traced in the
output window(true) or is returned as a string(false).
     * @param lineBreak a string indicating the type of line break to put in
the return string.
     * @return A string representation of this css sheet(if traceFile param
is false).
     */
    function dumpCSSFile(traceFile:Boolean, lineBreak:String)
    {
        var string:String;
        var styleNames = getStyleNames();
        var textList:Array = new Array();

        string = "/*" + lineBreak;
        string += lineBreak;
        string += "    Date of dumpFile :: " + new Date() + lineBreak;
        string += "    Instance Name :: " + __name + lineBreak;
        string += "    Number of Style Objects :: " + styleNames.length +
lineBreak;
        string += "    Style Names :: " + styleNames + lineBreak;

        if (__description != undefined) {
            string += lineBreak;
            string += __description;
            string += lineBreak;
        }

        string += lineBreak;
        string += "*/" + lineBreak;
        string += "" + lineBreak;

        for (var i = 0; i < styleNames.length; i++) {

            var styleName:String = styleNames[i];
            var styleObject:Object = getStyleObject (styleName);

            string += styleName + lineBreak;
            string += "{" + lineBreak;

            textList = new Array();

            var decore = styleObject.getStyleKeys();

            if (decore == undefined) {
                decore = styleObject; //this is due to xml being parsed as
just properties
            }

            //for (var propName in styleObject){
            for (var propName in decore) {

                var propValue = styleObject[propName];

                if (propName == '_tf') {
                    parseTFObject(propValue, textList);
                } else {

                    if (StyleManager.isColorStyle(propName)) {
                        propValue =
TEOUtility.convertDecimalToHexString(propName, propValue)
                    }

                    textList.push ("\t" +
TEOUtility.convertToCSSName(propName) + ":" + propValue + ";");
                }

            }

            for (var j = textList.length - 1; j >= 0; j--) {
                string += textList[j] + lineBreak;
            }

            string += "}" + lineBreak;
            string += lineBreak;
        }



        if (traceFile) { // if true, send it to the output window
            trace(string);
        } else {
            return string; // else return as a string
        }



    }





    function parseTFObject(tf:Object, textList:Array)
    {
        var bAll = true;
        var obj = new Object();
        for (var textProp in StyleManager.TextFormatStyleProps)
        {
            if (bAll || StyleManager.TextFormatStyleProps[textProp])
            {
                var cssName = CSSMap[textProp];
                var v = tf[textProp];

                if(textProp == "italic" && v != undefined)
                {
                    v = (v) ? "italic" : "normal";
                }
                else if(textProp == "bold" && v != undefined)
                {
                    v = (v) ? "bold" : "normal";
                }
                else if(textProp == "underline" && v != undefined)
                {
                    v = (v) ? "underline" : "normal";
                }
                else
                {
                    //bUndefined = true;
                }

                if (StyleManager.isColorStyle(textProp)) {
                    v = TEOUtility.convertDecimalToHexString(textProp, v)
                }

                if (v != undefined && v !=null) {
                    textList.push ("\t" +
TEOUtility.convertToCSSName(cssName) + ":" + v + ";");
                }

            }
        }
        return obj;
    }

    /**
     * Dumps a valid css file into the output window.
     * @param traceFile a boolean indicating if the file is traced in the
output window(true) or is returned as a string(false).
     * @param lineBreak a string indicating the type of line break to put in
the return string.
     * @return A string representation of this css sheet(if traceFile param
is false).
     * @todo NEEDS WORK ON VALIDATING TYPES
     */
    function dumpXMLFile(traceFile:Boolean, lineBreak:String)
    {
        var string:String = "<?xml version=\"1.0\"
encoding=\"iso-8859-1\"?>" + lineBreak;
        string += "<stylesheet>" + lineBreak;
        var styleNames = getStyleNames();
        var textList:Array = new Array();

        /*
        string = "/~" + lineBreak;
        string += lineBreak;
        string += "    Date of dumpFile :: " + new Date () + lineBreak;
        string += "    Instance Name :: " + __name + lineBreak;
        string += "    Number of Styles :: " + styleNames.length +
lineBreak;
        string += "    Style Names :: " + styleNames + lineBreak;
        if (__description != undefined){
            string += lineBreak;
            string += __description;
            string += lineBreak;
        }
        string += lineBreak;
        string += "~/" + lineBreak;
        string += "" + lineBreak;
        */

        var len = styleNames.length;
        for (var i = 0; i < len; i++) {
            var styleName:String = styleNames[i];
            var styleObject:Object = getStyleObject(styleName);
            // temp fix
            delete styleObject.styleKeys;

            string += "\t<" + styleName + lineBreak;

            textList = new Array ();

            var decore = styleObject.getStyleKeys();
            if (decore == undefined) {
                //this is due to xml being parsed as just properties
                decore = styleObject;
            }

            //for (var propName in styleObject){
            for (var propName in decore){

                if (propName == "setStyle" || propName == "_tf") {
                    continue;
                }

                var propValue = styleObject[propName];

                if (StyleManager.isColorStyle(propName)) {
                    propValue =
TEOUtility.convertDecimalToHexString(propName, propValue)
                }

                textList.push("\t\t" + propName + "=\"" + propValue + "\"");
            }

            // text styles
            ///* !!!!!!!!!!!!!!!!!!!!!
            for (var textName in StyleManager.TextStyleMap) {
                var propValue = styleObject[textName];

                if (propValue == null || propValue == undefined) {
                    continue
                }

                if (StyleManager.isColorStyle(textName)) {
                    propValue =
TEOUtility.convertDecimalToHexString(textName, propValue)
                }

                textList.push("\t\t" + textName + "=\"" + propValue + "\"");

            }
            //*/


            for (var j = textList.length - 1; j >= 0; j--) {
                string += textList[j];
                 if (j != 0) {
                     string += lineBreak
                 }
            }

            if (i == len - 1) {
                string += " />" + lineBreak;
            }
        }

        string += "</stylesheet>";

        if (traceFile) {
            trace (string);
        } else {
            return string;
        }
    }
    function toString():String
    {
        return "[ExternalStyleSheet]";
    }
}

ClassStyles - just ideas
----------------------------------------------------------------------

import com.teotigraphix.managers.UIStyleManager;

class com.teotigraphix.styles.ClassStyles extends Object
{
    private var __superClassPackageName:String = null;
    private var __superClassName:String = null;
    private var __classPackageName:String = null;
    private var __className:String = null;

    private var styles:Object;

    /**
    * TODO do this thing
    */
    function ClassStyles(classPackageName:String,
superClassPackageName:String)
    {
        styles = new Object();

        __classPackageName = classPackageName;

        var c:Array = __classPackageName.split(".");
        __className = c[c.length - 1];

        if (superClassPackageName != undefined) {
            __superClassPackageName = superClassPackageName;
            var s:Array = __superClassPackageName.split(".");
            __superClassName = s[s.length - 1];
        }
    }

    /**
     *
     * @usage
     * @return
     */

    function getClassPackageName()
    {
        return __classPackageName;
    }
    function getSuperClassPackageName()
    {
        return __superClassPackageName;
    }


    function getSuperClassName()
    {
        return __superClassName;
    }
    function getClassName()
    {
        return __className;
    }



    function getStyle(styleName:String)
    {
        var obj = styles[styleName];
        if (obj != undefined) {
            return obj;
        }
    }

    function getStylesObject()
    {
        return new Object(styles);
    }

    function addStyle(styleName:String, defaults:String, type:String,
component:String, comment:String)
    {
        if (styleName != undefined) {
            styles[styleName] = {name:styleName, defaults:defaults,
type:type, component:component, comment:comment};
        }
    }

    function removeStyle(styleName:String)
    {
        var obj = styles[styleName];
        if (obj != undefined) {
            delete styles[styleName];
        }
    }

    function traceStyles()
    {
        trace("styles");
    }

    function exportStyles(type:String)
    {
        switch(type) {
        case 'classdoc':
            exportClassDocs();
            break;
        }
        // this would be for product page and any other format html or
otherwise I need.
        // class COMMENT Backasswards BUT greate, fill in the construct
class, then generate it for the class head
        // before a compile!!! :) brb
    }

    function exportClassDocs():String
    {
        var string:String = " *\n";
        for (var styleName in styles) {
            var obj:Object = styles[styleName];
            string += " * @style " + styleName + " " + obj.type + " " +
obj.comment + "\n";
        }
        string += " * ";
        return string;
    }




    function exportClassStyleChain():String
    {
        return _exportClassStyleChain("");
    }

    function _exportClassStyleChain(string:String):String
    {
        string += "\n===============================\n| " +
getClassPackageName() + "\n===============================\n\n";

        for (var styleName in styles) {
            var styleO = styles[styleName];
            string += "\t" + styleName + " :: " + styleO.comment + "\n";
        }

        if (hasSuper()) {
            var sObj =
UIStyleManager.getClassStylesObject(getSuperClassPackageName());
            string += sObj.exportClassStyleChain(string);
        }

        return string;
    }

    public function hasSuper():Boolean
    {
        return (__superClassPackageName != null) ? true : false;
    }



    function exportStylesPHP():String
    {
        var string:String = "<h1>" + __className + " Styles</h1>";

        for (var styleName in styles) {
            var styleO = styles[styleName];
            string += getStylePHPBLock(styleName, styleO.type,
styleO.defaults, styleO.comment);
        }
        return string;
    }

    function getStylePHPBLock(styleName:String, type:String,
defaults:String, comment:String)
    {
        var string:String = "\n";

        string += "<h4><code>" + styleName + ":" + type + "</code></h4>\n";
        string += "<blockquote>\n";
        string += "  <p><strong>default</strong> : <em>'" + defaults + "'
</em></p>\n";
        string += "  <p>" + comment + "</p>\n";
        string += "</blockquote>\n";

        return string;
    }


    /*
string += "<h4><code>" + styleName + ":" + type + "</code></h4>";
string += "<blockquote>";
string += "  <p><strong>default</strong> : <em>'" + defaults + "'
</em></p>";
string += "  <p>" + comment + "</p>";
string += "</blockquote>";
    */

}






On 6/5/06, Jason Hawryluk <[EMAIL PROTECTED]> wrote:
yes exactly, basicly they load a bare bones application component with a
defined <mx:Style and boom all styles changed. I guess they replaced the
loaded style that was compiled in or somthing. Anyway that was flex 1.5, I
think... it's been a while, and i'm trying to do this in Flex 2. It did not
do any parseing of it at all which is why it rocked :)

Jason
-----Message d'origine-----
De : flexcoders@yahoogroups.com [mailto: [EMAIL PROTECTED] la
part de Michael Schmalle

Envoyé : lundi 5 juin 2006 15:07

À : flexcoders@yahoogroups.com
Objet : Re: [flexcoders] Runtime CSS Styles Flex 2.0 B3


Hmm,

I don't follow, you mean load a style sheet that changes fill color styles?

Peace, Mike


On 6/5/06, Jason Hawryluk <[EMAIL PROTECTED]> wrote:
I was thinking more along the lines of styles for components fill colors
etc. Someone had done it in Flex 1.5 and it was very slick or it may have
been in the alpha (can't recollect).

-----Message d'origine-----
De : flexcoders@yahoogroups.com [mailto: [EMAIL PROTECTED] la
part de Michael Schmalle
Envoyé : lundi 5 juin 2006 13:33
À : flexcoders@yahoogroups.com
Objet : Re: [flexcoders] Runtime CSS Styles Flex 2.0 B3


Hi,

Search the list, there are a couple of posts on this. You need to use the
styleSheet load of the TextField. Then custom parse through values. I am
sure there will be some class libraries for this in the future. Gordon Smith
(Adobe) hinted that there might also be this in a future version of Flex, I
am sure of this.

The 'apply' part of the algorithm is the hardest. I created this in Flash8
for components, havn't finished it to Flex2. When I do I will post the code
as it's kinda fun loading css from styleSheets at runtime ;-)

Peace, Mike


On 6/5/06, sourcecoderia <[EMAIL PROTECTED]> wrote:
Has anyone figured out a way to do runtime CSS file loading? Is it
possible? I know in Flex 1.5 it was, but the framework has changed so
extensively that I have not figured out a way to do it yet.

Any idea or help appreciated

Jason






--
Flexcoders Mailing List
FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.com



SPONSORED LINKS Web site design development Computer software development
Software design and development
Macromedia flex Software development best practice



YAHOO! GROUPS LINKS

 Visit your group "flexcoders" on the web.

 To unsubscribe from this group, send an email to:
  [EMAIL PROTECTED]

 Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service.







--
What goes up, does come down.

--
Flexcoders Mailing List
FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.com



SPONSORED LINKS Web site design development Computer software development
Software design and development
Macromedia flex Software development best practice



YAHOO! GROUPS LINKS

 Visit your group "flexcoders" on the web.

 To unsubscribe from this group, send an email to:
  [EMAIL PROTECTED]

 Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service.







--
What goes up, does come down.

--
Flexcoders Mailing List
FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.com



SPONSORED LINKS Web site design development Computer software development
Software design and development
Macromedia flex Software development best practice



YAHOO! GROUPS LINKS

 Visit your group "flexcoders" on the web.

 To unsubscribe from this group, send an email to:
  [EMAIL PROTECTED]

 Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service.







--
What goes up, does come down.

--
Flexcoders Mailing List
FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.com



SPONSORED LINKS Web site design development Computer software development
Software design and development
Macromedia flex Software development best practice



YAHOO! GROUPS LINKS

 Visit your group "flexcoders" on the web.

 To unsubscribe from this group, send an email to:
 [EMAIL PROTECTED]

 Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service.




------------------------ Yahoo! Groups Sponsor --------------------~--> 
Home is just a click away.  Make Yahoo! your home page now.
http://us.click.yahoo.com/DHchtC/3FxNAA/yQLSAA/nhFolB/TM
--------------------------------------------------------------------~-> 

--
Flexcoders Mailing List
FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.com 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/flexcoders/

<*> To unsubscribe from this group, send an email to:
    [EMAIL PROTECTED]

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/
 



Reply via email to