Apologies for the formatting..... email client messed it up
I want to mention another reason I did this , which was so that I could
'reload' particular images at run time easily, i.e. reload, recache and
then redraw all images using that particular bitmap, but that bit isn't
yet written :)
Matthew Cloy wrote:
I could never get resources to work like that...
What I ended up doing was to create my own image class that went 'low
level' flash to grab a copy of the loaded image, and then once cached
I attach it to the movie clip each time I use it, instead of reissuing
the request.
It's a flash-only (not to mention hacking at laszlo internals, and not
to be encouraged) solution, but it's the only way I found personally,
and speeds up my image loading considerably.
This code is only tested in 3.2cr2 btw.
Basic code for the loader is:
<class name="bitmapLoader" extends="view" visible="0">
<method event="onload">
this.bmo.bitmap = new
flash.display.BitmapData(this.resourcewidth,this.resourceheight,true,0x000000);
var matrix = new
flash.geom.Matrix();
matrix.identity();
this.bmo.bitmap.draw(this.getMCRef(),matrix);
this.bmo.width = this.resourcewidth;
this.bmo.height = this.resourceheight;
ProcessBMWindows(this.bmo);
</method>
</class>
Then I create my own "Ximage" subclass of view:
When the imagesrc attribute is set it checks if there's already a
bitmapLoader there, if not it creates one and then waits for the
callback to initialise it.
If it's there but isn't finished loading yet then it adds itself to
the list for later initialisation.
And if it's there, and loaded, then it uses it.
Below you can see this class , as well as the simple management code
around it.
<script> <![CDATA[
var bmList = new Array();
function CreateBM(w,s)
{
bmList[s] = new Object();
bmList[s].bitmap = 0;
bmList[s].windows = new Array();
bmList[s].depth = 0;
if (w)
bmList[s].windows.push(w);
bmList[s].loader = new bitmapLoader(canvas);
bmList[s].loader.bmo = bmList[s];
bmList[s].loader.setSource(s);
}
function AddBM(w,s)
{ bmList[s].windows.push(w);
}
function GetBM(s)
{
return bmList[s];
}
function ProcessBMWindows(bmo)
{
for (var i in bmo.windows)
{
bmo.windows[i].Attach(bmo);
} }
]]>
</script>
<class name="XImage" extends="view" > <attribute
name="imagesrc"/>
<attribute name="scaleto"/>
<attribute name="smoothing" type="number" value="0"/>
<method name="Attach" args="bmo">
var mcRef = this.getMCRef();
mcRef.attachBitmap(bmo.bitmap, bmo.depth,"Never",smoothing);
this.resourcewidth = bmo.width;
this.resourceheight = bmo.height;
if (this["scaleto"])
{
if (this.scaleto=="width" || this.scaleto=="both")
this._setrescwidth = 1;
if
(this.scaleto=="height" || this.scaleto=="both")
this._setrescheight = 1;
}
if (this.hassetwidth)
mcRef._xscale = (this.width / this.resourcewidth) *
100; if (this.hassetheight)
mcRef._yscale = (this.height / this.resourceheight) *
100; this.reevaluateSize( );
</method>
<method event="oninit">
//???
this.onimagesrc.sendEvent();
</method>
<method event="onimagesrc">
if (this["imagesrc"])
{
var bm = GetBM(this.imagesrc);
if (!bm)
{
CreateBM(this,this.imagesrc);
}
else
{ if (!bm.bitmap)
AddBM(this,this.imagesrc);
else
{
this.Attach(bm);
}
}
}
</method>
</class>
P T Withington wrote:
That would be a bummer if it could not. But I don't know. I guess
you would have to try it (and file a bug if it doesn't work :).
On 2007-02-08, at 18:25 EST, Jeff Paquette wrote:
But a resource can't be bound to a datapath, can it?
-----Original Message-----
From: P T Withington [mailto:[EMAIL PROTECTED]
Sent: Thursday, February 08, 2007 11:35 AM
To: Jeff
Cc: [email protected]
Subject: Re: [Laszlo-user] how to cache image from dataset?
Not so. You can have a resource that is loaded at run time.
If the src is an http URL, the resource will be loaded at run time.
On 2007-02-08, at 10:45 EST, Jeff wrote:
I did a resource, but then the images have to be compiled
in, right? I
need the graphics to be external.
On Thu, February 8, 2007 10:40 am, P T Withington wrote:
Have you tried using a resources? I believe you can parameterize a
resource. Probably the most natural thing to do is make a resource
with several frames that represent the states and then display the
appropriate frame.