A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: apply external css to extenal text

  1. #1
    Webmong
    Join Date
    Mar 2004
    Location
    London UK
    Posts
    24

    apply external css to extenal text

    I found this that loads on external css file:

    code:

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

    //Specify the location of the CSS file that you created earlier
    var cssURL = "example.css";


    //Hard code some HTML text to display (for example purposes)
    exampleText = "<p class='headline'>Tutorial Takes Forever To Write</p>";
    exampleText += "<p><span class='byline'>Bath, UK</span>";
    exampleText += "--Flash developer NWebb seemed to take ";
    exampleText += "forever to finish his CSS-Flash tutorial, ";
    exampleText += "but it is finished now and you can find it ";
    exampleText += "<a href='http://www.nwebb.co.uk'>here</a> ";
    exampleText += "along with a few others.</p>";


    //Load CSS file
    myCSS.load(cssURL);
    //define onLoad handler
    myCSS.onLoad = function(success) {
    if (success) {
    /* If the style sheet loaded without error,
    assign it to the text object, and assign the HTML text to the
    text field*/
    myText.styleSheet = myCSS;
    myText.text = exampleText;
    }
    };



    And i use this to load some external text:
    code:

    loadVariables("content/pages/page.lang.php?page=home&type=FLA&lang="+_root.lang , this);



    with the external text I just created a 'dynamic' text box and set the 'Var:' the the properties box to '_root.Vhome1'.

    'Vhome1' is the variable that the php script prints.

    what I need to do is aply the css to the externaly loaded text.

    I tried this:

    code:

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

    //Specify the location of the CSS file that you created earlier
    var cssURL = "example.css";

    loadVariables("page.lang.php?page=home&type=FLA&la ng="+_root.lang, this);
    exampleText = _rootVhome1;

    //Load CSS file
    myCSS.load(cssURL);
    //define onLoad handler
    myCSS.onLoad = function(success) {
    if (success) {
    /* If the style sheet loaded without error,
    assign it to the text object, and assign the HTML text to the
    text field*/
    myText.styleSheet = myCSS;
    myText.text = exampleText;
    }
    };




    But it didn't work.

    Any ideas?

    Cheers
    Chris

  2. #2
    try it the other way around... You now have
    code:

    //Load CSS file
    myCSS.load(cssURL);
    //define onLoad handler
    myCSS.onLoad = function(success) {
    if (success) {
    /* If the style sheet loaded without error,
    assign it to the text object, and assign the HTML text to the
    text field*/
    myText.styleSheet = myCSS;
    myText.text = exampleText;
    }
    };



    In this way you FIRST load the CSS then define an on_load method.

    This can cause timeing problems. so try this:

    code:


    //define onLoad handler
    myCSS.onLoad = function(success) {
    if (success) {
    /* If the style sheet loaded without error,
    assign it to the text object, and assign the HTML text to the
    text field*/
    myText.styleSheet = myCSS;
    myText.text = exampleText;
    }
    };
    //Load CSS file
    myCSS.load(cssURL);


  3. #3
    Webmong
    Join Date
    Mar 2004
    Location
    London UK
    Posts
    24
    Thanks mate

    I can't get it to work with the externaly loaded text.

    code:

    loadVariables("content/pages/page.lang.php?page=home&type=FLA&lang="+_root.lang , this);



    any ideas how I can load the external text and then apply the external css to it.

    Cheers
    Chris
    Successful people ask better questions, and as a result, they get better answers - Anthony Robbins

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center