image.lzx
<library>
<class name="image">
<attribute name="prefix" value="
" type="string"/>
<attribute name="src" value="
" type="string"/>
<attribute name="lastloaded" value="
" type="string"/>
<attribute name="forcereload" value="false
" type="boolean"/>
<method name="applyData" args="d">
if (d != null) this.setAttribute('src', d);
</method>
<event name="onsrc"/>
<handler name="onsrc" method="loadNow"/>
<method name="loadNow" args="img">
// don't reload the same thing unless we're told to
var url = this.prefix + img;
if (this.forcereload || this.lastloaded != url) {
this.lastloaded = url;
this.setSource( url );
}
</method>
<method name="init">
super.init();
if (this.src != '' && this.src != null)
this.loadNow(this.src);
</method>
<doc>
<tag name="shortdesc"><text>A way to import images</text></tag>
<text>
<example title="image">
<canvas debug="true">
<dataset name="imagedata">
<image url="http://www.openlaszlo.org/images/horses/horse-1-sm.jpg"/>
</dataset>
<wrappinglayout/>
<image src="http://www.openlaszlo.org/images/horses/horse-1-sm.jpg"/>
<image datapath="imagedata:/image/@url"/>
<image prefix="http://www.openlaszlo.org/images/horses/" src="horse-1-sm.jpg"/>
<image src="http://www.openlaszlo.org/images/horses/horse-1-sm.jpg"/>
<image>
<text>Click me</text>
<handler name="onclick">
this.setAttribute('src', 'http://www.openlaszlo.org/images/horses/horse-1-sm.jpg');
</handler>
</image>
<image forcereload="true">
<text>Click me to reload</text>
<handler name="onclick">
this.setAttribute('src', 'http://www.openlaszlo.org/images/horses/horse-1-sm.jpg');
</handler>
</image>
</canvas>
</example>
</text>
</doc>
</class>
</library>