[Laszlo-dev] Dynamic libraries and resources

Oliver Steele steele at laszlosystems.com
Fri Jan 7 14:17:25 PST 2005


Consider an application that consists of two files, a canvas file and a 
library file.  The canvas file imports the library file.  (In order to 
show this I'll show some syntax, but this is actually a bit different 
from the 3.0b1 syntax --- again, I'll post on that separately.)

canvas.lzx:
   <canvas>
     <import href="library.lzx"/>
     <myclass/>
   </canvas>

library.lzx:
   <library>
     <class name="myclass" width="10" height="10" bgcolor="red"/>
   </library>

The implementation strategy is that canvas.lzx compiles into a file 
canvas.swf, and library.lzx compiles into library.swf.  When it 
executes, canvas.swf loads library.swf, which executes the code 
therein.  This has the side effect of defining the class myclass.  
(What's implemented now doesn't actually do this.  The library has to 
be explicitly loaded via script, and the class therefore can't be 
instantiated except as script.)

This mechanism works for classes, instances, and datasets.  It doesn't 
work for resources.  Consider the single-file case.  This displays a 
view that presents the image in logo.jpg.
   <canvas>
     <resource name="logo" src="logo.jpg"/>
     <class name="myclass" resource="logo"/>
     <myclass/>
   </canvas>

The dynamic library case ought to work the same way:

canvas.lzx:
   <canvas>
     <import href="library.lzx"/>
     <myclass/>
   </canvas>

library.lzx:
   <library>
     <resource name="logo" src="logo.jpg"/>
     <class name="myclass" resource="logo"/>
   </library>

The problem is that resources defined in one file (library.swf) don't 
work in another (canvas.swf).

The reason has to do with the implementation of resources in Flash 
files, which is something like the following.  Beware: I'm not one of 
the Flash runtime gurus here, and I may have some of the details wrong. 
  Someone who has worked more on the client runtime library can chime in 
here if this is off.

Compile-time Laszlo resources are represented as Flash characters.    
(Characters are also sometimes referred to definitions, symbols, or 
assets.) The <resource> element defines a resource named "logo", whose 
value is the (possibly transcoded) content of the file "logo.jpg".  
This resource (the name, and the content) is compiled into the canvas 
executable.  In the Flash implementation, this is implemented as a 
Flash character whose name is the <resource> name.

Laszlo views are represented as JavaScript objects, with Flash movie 
clips as peers.  (The movie clips represents the object within the 
Flash display list.)  attachMovie is used to set a view's 
resource/attach a character to a clip.

Each Flash file has a character table.  The character id is resolved 
against the table in the Flash file that contains the movie clip that 
the character is attached to.  Movie clips are copied from clips in 
main.swf, so any character names are looked up in the character table 
in main.swf.  This means a resource compiled into library.swf won't 
appear.

One swf can import characters that another swf has exported.  The 
exporting swf simply lists the character ids and their export names.  
The importing swf names the url of the exporting swf, the export names 
of the exported characters, and the ids by which they're referred to 
locally.

Unfortunately, the swf import/export mechanism isn't useful in dynamic 
libraries, because the import tag must appear in the swf control tag 
stream (import can't be executed programatically), and it loads the url 
immediately.

We've been trying out other solutions.  I'll send one in the next 
message.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: text/enriched
Size: 3752 bytes
Desc: not available
Url : http://www.openlaszlo.org/pipermail/laszlo-dev/attachments/20050107/d6893379/attachment.bin


More information about the Laszlo-dev mailing list