0
votes

I'm trying to include a long string in an external file using the following syntax:

<fx:String id="myText" source="examples/text.txt" />

But it's generating an error:

1084: Syntax error: expecting identifier before rightparen. 

Is there something I'm missing?

I've seen similar for embedding a text file using ActionScript but I would like to embed a string value using MXML.

I've found this example on Flex help docs:

<fx:String id="myStringProperty1" source="./file"/>

I can't see anything that I'm doing differently.

1

1 Answers

0
votes

OK I found the cause. In my external file I have a few curly braces. The compiler is getting hung up on those.

Here is the contents of my external file:

<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"> 
    <head>
        <style type="text/css" media="screen"> 
            html, body  {
                height:100%;
            }
        </style>
    </head>
</html>

The part where it has body { height:100% } it is interpreting it as data binding. Here is the generated ActionScript:

    result[1] = new mx.binding.Binding(this,
        function():String
        {
            var result:* = "<html xmlns=\"http://www.w3.org/1999/xhtml\" lang=\"en\" xml:lang=\"en\"> \n    <head>\n        <style type=\"text/css\" media=\"screen\"> \n            html, body  " + (
            height:100%;
        ) + "\n        </style>\n    </head>\n</html>";
            return (result == undefined ? null : String(result));
        },
        null,
        "HTML"
        );

As you can see it thinks I'm using data binding between the curly braces. Since I'm not, it's throwing an error because "height:100%" is out of context where it's being used.

I think I will have to try a different method to embed this text. It seems to be fine if I use this but I rather not:

<fx:String id="HTML">
    <![CDATA[<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"> 
    <head>
        <style type="text/css" media="screen"> 
            html, body  {
                height:100%;
            }
        </style>
    </head>
    </html>]]>
</fx:String>

UPDATE!!!
I WAS WRONG! It is possible. I have to escape at least the opening curly brace and then it works.

Contents of file that works:

<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"> 
    <head>
        <style type="text/css" media="screen"> 
            html, body  \{
                height:100%;
            \}
        </style>
    </head>
</html>