PDA

View Full Version : Including resources in a file


cmcginnis
01-30-2003, 03:31 PM
Lets say that I have a large application with many resources and I want to put them in a separate file and include it. For example:

Instead of this:

<canvas title="Example 1" id="Example1" debug="false">
<resource name="vertLine" src="resources/vert_line.swf"/>
<resource name="horizLine" src="resources/horiz_line.swf"/>
<view name="line" visible="true" resource="horizLine"/>
</canvas>

Do this:

<canvas title="Example 1" id="Example1" debug="false">
<include href="resources.lzx"/>
<view name="line" visible="true" resource="horizLine"/>
</canvas>

But when I try and view the page I get the "root element must be well formed" error message. It works when I wrap the resources with a <library> tag, but the documentation for the tag say that I should never use the library tag in a user program. So what should I do?

Also, if I set the include type to "xml" I get a warning saying that it is not needed, even though its documented that the attribute can be set, and it is including a lzx file.

Thanks
Chris

antun
01-30-2003, 04:11 PM
Hey Chris

Where did you read the documentation that says that you can't use a <library> tag in a user file? In fact, you can (and it's good form to use it).

You have got the correct idea for its use.

As for the type="xml" attribute being not needed, I'm going to look into that. You should not need to use it when including an LZX file.

-Antun

cmcginnis
01-30-2003, 05:42 PM
Thanks, for the reponse. So I realized that it is the href attribute of the library tag that shouldn't be used, not the tag itself - my bad.

So my question still remains on why the library is even needed in the first place? What is it's purpose? I always imagined the include tag to be a kind of "copy everything from the specified file into the the current file right before compilation" kind of thing, but if that was the case then it should work without the library tag. So why doesn't the following work?

main.lzx
------------
<canvas>
<include href="resources.lzx"/>
</canvas>

resources.lzx
-------------
<resource name="resource1" src="foo.swf"/>
<resource name="resource2" src="bar.swf"/>


Why do I need the library tag for this to work when I don't need to use the library tag when including views?

Thanks again for the help
Chris McGinnis

antun
02-03-2003, 03:41 PM
Hey Chris

One issue is that without the <library> tag, the included document would not be valid XML (no root node), and the parser will complain, so whilst you could include this:-

myInclude.lzx

<view name="myWindow" width="500" height="430">
<!-- lots of subviews here -->
</view>


You could NOT include this:-

myInclude.lzx

<view name="myWindow" width="500" height="430">
<!-- lots of subviews here -->
</view>
<view name"mySecondwindow">
<!-- more commented out code -->
</view>


In short, a library tag prevents code from being included twice. You should use it for class definitions (but you can use it for resources too).

-Antun