4 Replies Latest reply on Nov 10, 2009 5:43 AM by spireality

    Loading CSS into Flash


      This code seems totally legit to me:




      info_txt1.html = true;
      info_txt1.multiline = true;
      info_txt1.wordWrap = true;
      info_txt1.condenseWhite = true;


      info_txt2.html = true;
      info_txt2.multiline = true;
      info_txt2.wordWrap = true;
      info_txt2.condenseWhite = true;


      var myCSS = new TextField.StyleSheet();
      var cssURL = "style_dtf.css";




      myCSS.onLoad = function(success) {
          if (success) {
              info_txt1.styleSheet = myCSS;
              info_txt2.styleSheet = myCSS;
              trace("CSS file loaded successfully. You may proceed.");
          } else {
              trace("CSS file failed to load!");



      My CSS file is deffinitly in the folder with the SWF - and the FLA for the matter, and I keep getting my, "CSS file failed to load!"




      Text files content loads from XML - working fine:


      var infoXML:XML = new XML();
      infoXML.ignoreWhite = true;
      var output1:String = "";
      var output2:String = "";


      infoXML.onLoad = function(success) {
          if (success) {
              var info:Array = infoXML.firstChild.childNodes;
              output1 += info[0].childNodes[0];
              output1 += info[0].childNodes[1];
              info_txt1.htmlText = output1;
              trace("XML load.");
              if (success) {
              var contact:Array = infoXML.firstChild.childNodes;
              output2 = contact[0].childNodes[2];       
              info_txt2.htmlText = output2;
              trace("XML load.");
              info_txt.htmlText = ("XML file did not load.");





      And no formatting is taking place.

        • 1. Re: Loading CSS into Flash
          Ned Murphy Adobe Community Professional & MVP

          Are you testing this as a stand alone swf in the Flash editor or via a browser?  If a browser, is the swf in the same directory as the html page?

          • 2. Re: Loading CSS into Flash
            spireality Level 1

            Just testing in Flash so far...

            • 3. Re: Loading CSS into Flash
              Ned Murphy Adobe Community Professional & MVP

              I don't see anything wrong with the code, though it is better practice to define the onLoad function before you command the load to occur.  What you might do is reduce what you're doing to only dealing with loading the css file by commenting out the rest of the code.  That will at least insure nothing else is possibly interfering with the loading process since you are loading multiple files otherwise.

              1 person found this helpful
              • 4. Re: Loading CSS into Flash
                spireality Level 1

                Okay - thanks.


                The really bizarre thing to me is that I got this simple tutorial:




                I pasted the exact AS onto my stage:


                // set up the textfield attributes
                myTextField_txt.html = true;
                myTextField_txt.wordWrap = true;
                myTextField_txt.multiline = true;
                myTextField_txt.condenseWhite = true;

                // create new style sheet object
                var myCSS = new TextField.StyleSheet();


                // specify the location of your existing CSS file
                var cssURL = "example_2.css";


                // load CSS file


                // define onLoad handler
                myCSS.onLoad = function(success) {
                    if (success) {
                        /* if the style sheet loaded without error */
                        myTextField_txt.styleSheet = myCSS;
                        myTextField_txt.text = "CSS file loaded successfully. You may proceed.";
                    } else {
                        myTextField_txt.text = "CSS file failed to load!";


                //load the XML file
                myContent = new XML();
                myContent.ignoreWhite = true;
                myContent.onLoad = function(success) {
                    if (success) {
                        myTextField_txt.text = myContent;
                    } else {
                        myTextField_txt.text += "<br /> XML file failed to load!";



                Then I  swap out the css file name with what I have - style_dtf.css - and it doesn't error (no output regarding CSS), but it shows ALL the code from the XML file in a big string, with all the tags and everything.


                Very weird...


                I even pasted the CSS from the example file into the beginning of my CSS file and still same effect.


                I do have all my SWFs in a seperate folder, but for now I just duplicated my CSS and XML into both folders.