I didn't tried it, but from help, this should work :
 
package {
    import flash.display.Sprite;
    import flash.text.StyleSheet;
    import flash.text.TextField;
    import flash.text.TextFieldAutoSize;

    public class StyleSheetExample extends Sprite {

        public function StyleSheetExample() {
            var style:StyleSheet = new StyleSheet();

            var heading:Object = new Object();
            heading.fontWeight = "bold";
            heading.color = "#FF0000";

            var body:Object = new Object();
            body.fontStyle = "italic";

            style.setStyle(".heading", heading);
            style.setStyle("body", body);

            var label:TextField = new TextField();
            label.styleSheet = style;
            label.htmlText = "<body><span class='heading'>Hello </span>World...</body>";
            addChild(label);
        }
    }
}
 
******
 
Of course this is not what you want, as it does not use an external CSS.
Now, i guess that using the parseCSS Method could get you where you want to go. Not sure though... :s
 
This is not dynamically loading CSS at runtime which is not possible as we speak, as Tom said.
 
Share your findings on this.
 
Best,
JL
 
--
Lancement de la communauté francophone sur Flex :
http://www.flexeurs.org > rejoignez-nous !
 
 
----- Original Message -----
Sent: Monday, July 17, 2006 2:02 PM
Subject: [flexcoders] Loading external css and setting a:hover style for htmlText

How do I connect an external stylesheet to a textfield so the htmlText
gets the right styles?

In Flex 1.5 that was easy:

var styles:TextField.StyleSheet = new TextField.StyleSheet();
styles.load('myStyles.css');
...
function onLoad(ok){
if(ok){
myText.htmlText = "hello <a href="">world</a>
myText.styleSheet = styles
}
}

But how to do this in Flex 2.0, when function 'load()' doesn't exist
anymore and parseCSS not realy seems tow work with a:hover style etc?

In the 2.0 example I have an Application...

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
xmlns:myText="*" layout="absolute">
<mx:Style source="main.css "/>
<myText:TextFieldExample />
</mx:Application>

...that loads an external stylesheet main.css,...

body {
fontFamily : "ThesisBolPla";
leading : "-3";
}
.heading {
fontWeight :"bold";
color: "#FF3300";
}
a {
color:#f0037f;
}
a:link{
color:#f0037f;
text-decoration:underline;
}
a:hover{
color:#f0037f;
}
a:active{
color:#cccccc;
}

...and creates the an instance of TextFieldExample:

package {
import mx.core.UIComponent;
import flash.text.TextField;

public class TextFieldExample extends UIComponent {

private var label:TextField;
private var labelText:String = "<body><span
class='heading'>Hello world</span><br><a href=''>and
welcome</a> to the show. </body>";

public function TextFieldExample() {
configureLabel();
setLabel(labelText);
}

public function setLabel(str:String):void {

label.htmlText = str;
}

private function configureLabel():void {

label = new TextField();
label.width = 200;
label.embedFonts = true;
label.background = "">label.multiline = true;
label.styleSheet = HOW TO CONNECT TO THE CSS?;

addChild(label);
}
}
}

How do I connect the external stylesheet to the textfield so the
htmlText gets the right style?

__._,_.___

--
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




__,_._,___

Reply via email to