[Laszlo-dev] Fwd: some tantalizing comments about loading
assetsfrom external swfs
Henry Minsky
henry.minsky at gmail.com
Mon Jan 10 06:53:35 PST 2005
By the way, this is the syntax which is currently supported in the 3.0
development tree
for loadable libraries. It uses the <import> tag to declare a
LzLibrary object, which can then be loaded by calling it's load()
method. The compiler will compile each imported library as a
standalone swf file, which includes code, resources, and data but not
the LFC runtime.
The model is similar to that of loading data; a swf file is loaded
into a LzLoader object by using a movieclip as an attachment point and
calling loadMovie() to load the swf file.
(The library loading mechanism and syntax is not finalized and likely
to change before the final 3.0 release, but this is what is
implemented now)
Loading of library class definitions, instances, <script> blocks, and
inline data are working , but we're trying to figure out the right way
to handle attaching of flash definitions from the library file, hence
my previous question..
main.lzx:
<canvas width="1024" height="600" embedfonts="false">
<debug x="200" y="20" width="600" height="300" fontsize="12" />
<import href="lib.lzx" name="mylib" id="foobar" >
<method event="onload" args="a">
Debug.write('snippet loaded!');
Debug.showInternalProperties = true;
</method>
</import>
<view id="foo" y="200">
<simplelayout/>
<button onclick="mylib.load()" >load mylib</button>
<button onclick="canvas.showme()" >showme()</button>
</view>
<method name="showme" args="">
new LzView(canvas, {id: "v1" , resource: "myimage", x: 200});
</method>
</canvas>
lib.lzx:
<library>
<resource src="myimage.jpg" name="myimage" />
<view id="libview" width="100" height="100" bgcolor="red">
<text>loaded lib-rsrc.swf</text>
</view>
<script>
debug.write("-- loaded lib-rsrc.swf !");
</script>
</library>
On Mon, 10 Jan 2005 09:15:30 -0500, Cortlandt Winters
<cort at notebookmargins.com> wrote:
> Hi Henry,
>
> I think that, as you suspect, the post is a little misleading here for your
> purposes. He's not attaching the dynamically loaded library symbol to the
> scope of the original loading timeline. He's just calling a function on the
> scope of the loaded movieclip which can attach it's own library symbols and
> be displayed as a result. This will work though.
>
> So if you have Main.swf loading Assets1.swf Main can attach it's symbol's
> dynamically and Assets1 can attach it's symbols dynamically, but Main can't
> attach Assest1's symbols to it's scope, the best it can do is call a
> function in Assets, have it attach a symbol to it's local scope and then
> manipulate the Assets1.swf.
>
> This obviously could create problems if you have 2 symbols from the
> Assets1.swf that you are trying to manipulate simultaneously and
> independently. You could duplicate the library swf, but that would be a
> waste of memory for anything large, so I'm afraid lz would probably want to
> load them each as independent swfs unless the assets are really small.
>
> If you would like a simple example to look at I can create one either at
> lunch or this evening if nobody does so before then.
>
> -Cort
>
> > -----Original Message-----
> > From: laszlo-dev-bounces at openlaszlo.org
> > [mailto:laszlo-dev-bounces at openlaszlo.org]On Behalf Of Henry Minsky
> > Sent: Sunday, January 09, 2005 10:22 PM
> > To: OpenLaszlo platform development and bug reporting
> > Subject: [Laszlo-dev] Fwd: some tantalizing comments about loading
> > assetsfrom external swfs
> >
> >
> > This is a question addressed to anyone with Flash development expertise.
> >
> > We're looking at the issue of loading libraries or "modules" at
> > runtime, using the "loadMovie()" command, and have been
> > having been trying to figure out the right way to be allow the main
> > app to access assets such as images which are defined inside of the
> > runtime-loaded library (swf file).
> >
> > In LZX resources are declared as
> >
> > <resource src="clock.jpg" name="gclock" />
> >
> > and the compiler will add this as a definition in the library swf
> > file, creating an ExportAssets tag for it. The question is, how can we
> > access these library file definitions from the main app? The library
> > swf file itself has been loaded via a loadMovie() call and attached to
> > a special placeholder movieclip belonging to a LzLoader object.
> >
> > In the guts of LzView, the code to attach a resource by name
> > ultimately calls attachMovie() with the name of the resource.
> >
> > I saw the following user comments on the Macromedia docs site, where
> > someone claims to be able to access the assets from a runtime-loaded
> > movieclip. Their suggestion, as I understand it, is to define a
> > function which calls attachMovie but is defined as a methd on the
> > library movieclip, and thus somehow has access to its flash dictionary
> > namespace.
> >
> > I tried to do these steps by hand, but was still unable to attach
> > image resources from the library file after it had been loaded. Does
> > anyone know if the code mechanism described below really ought to
> > work ?
> >
> >
> >
> > ========================================
> >
> >
> >
> >
> > http://livedocs.macromedia.com/flash/mx2004/main_7_2/wwhelp/wwhimp
> > l/common/html/wwhelp.htm?context=Flash_MX_2004&file=00001491.html
> >
> >
> >
> > Yes, the linked clip MUST be in the library of the clip calling
> > attachMovie.
> >
> > The work arounds I've done usually include something like
> > attaching a function to the clip that has the library item and having
> > it attach to the other clip. IE:
> >
> > // clip that wants the to do the attaching defines a generic
> > function on the clip that has the item in it's library:
> >
> > _level0.clipWIthLibraryItem.attachItem = function(target_mc, sName)
> > {
> > var mc:MovieClip = target_mc.attachMovie("linkageID", "newName",
> > target_mc.getNextHighestDepth());
> > return mc;
> > }
> >
> > var new_mc:MovieClip =
> > _level0.clipWIthLibraryItem.attachItem(this, "newName");
> >
> > this is off the top of my head, but I've done it serveral times.
> > If you have questions, please email me: johng at acmewebworks.com
> >
> > JohnGrden said on Nov 5, 2004 at 7:48 AM :
> >
> > you can't attach a dynamically created clip. what you probably
> > need to do is create a class that creates your clips so that it can be
> > called from anywhere you need it. You could even prototype a global
> > function if need be:
> >
> > _global.createClip = function(sNameOfClip, target_mc)
> > {
> > var mc:MovieClip = target_mc.createEmptyMovieClip(sNameOfClip,
> > target_mc.getNextHighestDepth());
> > return mc;
> > }
> >
> > questions: johng at acmewebworks.com
> > _______________________________________________
> > Laszlo-dev mailing list
> > Laszlo-dev at openlaszlo.org
> > http://www.openlaszlo.org/mailman/listinfo/laszlo-dev
>
> _______________________________________________
> Laszlo-dev mailing list
> Laszlo-dev at openlaszlo.org
> http://www.openlaszlo.org/mailman/listinfo/laszlo-dev
>
More information about the Laszlo-dev
mailing list