9 Replies Latest reply on Nov 17, 2009 12:18 PM by kglad

    CSS isn't changing XML File

    csa

      I'm working on the example attached trying to get my css to alter the colour of my xml links. Despite doing what the forums say you should it's not working. What am I doing wrong? Thanks

       

      <?xml version="1.0" encoding="ISO-8859-1"?>
      <?xml-stylesheet type="text/css" href="style.css"?>

        • 1. Re: CSS isn't changing XML File
          kglad Adobe Community Professional & MVP

          is that supposed to load style.css without parsing the xml in flash?  if so, where have you seen that?

          1 person found this helpful
          • 2. Re: CSS isn't changing XML File
            csa Level 1

            Not sure what you mean but on all the tutorials all it mentions is if you add the following code:

             

            <?xml version="1.0" encoding="ISO-8859-1"?>
            <?xml-stylesheet type="text/css" href="style.css"?>

             

            Create your style.css then it should work. I haven't seen (or I'm missed) whether there's another step that's required...although I guess there must be which is why it doesn't work.

            • 3. Re: CSS isn't changing XML File
              kglad Adobe Community Professional & MVP

              is that for flex?

               

              normally, in flash you load your stylesheet into a stylesheet instance.  xml has nothing to do with it unless you're loading the path to the css file in your xml file which wouldn't serve much purpose unless the css path/name was going to change and you wanted to do that by editing an xml file instead of the fla.

              • 4. Re: CSS isn't changing XML File
                csa Level 1

                think we're both getting confused!

                 

                I have a flash document with some dynamic text. The content of that text is being called from the xml file. I would like the dynamic text to be styled. Tutorials like: http://www.macloo.com/examples/flash/CSS_in_Flash/css_with_xml.html give examples but I'm stuggling to get them to work. Based on my zipped document - how should this be done?

                • 5. Re: CSS isn't changing XML File
                  kglad Adobe Community Professional & MVP

                  you need to use:

                   

                  var myCSS = new TextField.StyleSheet();

                  myCSS.load(style.css);

                   

                  // define onLoad handler
                  myCSS.onLoad = function(success) {
                      if (success) {

                   

                          myTextField_txt.styleSheet = myCSS; // where myTextField_txt is your textfield's instance name
                          // call a funciton to assign your text to myTextField_txt
                      } else {
                          myTextField_txt.text = "CSS file failed to load!";
                      }
                  }

                  1 person found this helpful
                  • 6. Re: CSS isn't changing XML File
                    csa Level 1

                    I assume I put this code at the bottom of my current AS?

                     

                    When I run the fla I get the following message:

                     

                    Error opening URL "file:///C|/Documents%20and%20Settings/Jen/Desktop/xml/undefined"

                     

                    It still displays my xml info but there is no colour change. This is how my current AS is looking:- Thanks

                     

                    function loadXML(loaded) {
                    if (loaded) {
                    _root.inventor = this.firstChild.childNodes[0].childNodes[0].firstChild.nodeValue;
                    _root.comments = this.firstChild.childNodes[0].childNodes[1].firstChild.nodeValue;
                    name_txt.text = _root.inventor;
                    comment_txt.htmlText = _root.comments;
                    } else {
                      trace("file not loaded!");
                    }
                    }
                    xmlData = new XML();
                    xmlData.ignoreWhite = true;
                    xmlData.onLoad = loadXML;
                    xmlData.load("inventors.xml");

                    var myCSS = new TextField.StyleSheet();

                    myCSS.load(style.css);


                    // define onLoad handler
                    myCSS.onLoad = function(success) {
                        if (success) {


                            name_txt.styleSheet = myCSS; // where myTextField_txt is your textfield's instance name
                            // call a funciton to assign your text to myTextField_txt
                        } else {
                            name_txt.text = "CSS file failed to load!";
                        }
                    }

                    • 7. Re: CSS isn't changing XML File
                      kglad Adobe Community Professional & MVP

                      that should be:

                       


                       

                      function loadXML(loaded) {
                      if (loaded) {
                      _root.inventor = this.firstChild.childNodes[0].childNodes[0].firstChild.nodeValue;
                      _root.comments = this.firstChild.childNodes[0].childNodes[1].firstChild.nodeValue;
                      name_txt.text = _root.inventor;
                      comment_txt.htmlText = _root.comments;
                      } else {
                        trace("file not loaded!");
                      }
                      }
                      xmlData = new XML();
                      xmlData.ignoreWhite = true;
                      xmlData.onLoad = loadXML;

                      var myCSS = new TextField.StyleSheet();

                      myCSS.load("style.css");


                      // define onLoad handler
                      myCSS.onLoad = function(success) {
                          if (success) {


                              name_txt.styleSheet = myCSS;
                          xmlData.load("inventors.xml");

                          } else {
                              name_txt.text = "CSS file failed to load!";
                          }
                      }

                      • 8. Re: CSS isn't changing XML File
                        csa Level 1

                        Sorry not been back in touch sooner.

                         

                        I still got an error...however I changed the AS so perhaps that's why. In the end I just added a html tag within my xml as my text didn't need much styling. However I will try this again as I need to know how to do this. Thank you for your help. Much appreciated.

                        • 9. Re: CSS isn't changing XML File
                          kglad Adobe Community Professional & MVP

                          you're welcome.