antun
08-14-2003, 03:55 PM
If you're loading images at runtime, there's usually a delay while the image loads. It's helpful to give your user a visual indicator to let them know that something is loading. In this example there is a spinning clock .swf file that is to be displayed when loading commences, then removed, and the new image is visible.
<canvas>
<simplelayout spacing="2" />
<text>Click the area below...</text>
<view name="loader" bgcolor="0x000000" width="300" height="200"
clickable="true">
<view name="loadIndicator" resource="clock.swf" visible="false" />
<view name="image" width="300" height="200"
stretches="both">
<method event="onload">
this.parent.loadIndicator.setVisible( false );
</method>
</view>
<method event="onclick">
this.loadIndicator.setVisible( true );
var u = 'http:big_photo.jpg';
this.image.setSource( u );
</method>
</view>
</canvas>
Note: You need to supply your own photo (big_photo.jpg) for this tip. I took the biggest photo I had and put it on a remote server to make the delay as noticeable as possible. The client will usually cache it after that, so subsequent requests will be quicker.
Whatever event starts the loading of image should also make the loading indicator visible. The indicator is later hidden when the onload event of the view that holds the image is fired. The onload event is fired when that view attaches its resource.
Enjoy!
<canvas>
<simplelayout spacing="2" />
<text>Click the area below...</text>
<view name="loader" bgcolor="0x000000" width="300" height="200"
clickable="true">
<view name="loadIndicator" resource="clock.swf" visible="false" />
<view name="image" width="300" height="200"
stretches="both">
<method event="onload">
this.parent.loadIndicator.setVisible( false );
</method>
</view>
<method event="onclick">
this.loadIndicator.setVisible( true );
var u = 'http:big_photo.jpg';
this.image.setSource( u );
</method>
</view>
</canvas>
Note: You need to supply your own photo (big_photo.jpg) for this tip. I took the biggest photo I had and put it on a remote server to make the delay as noticeable as possible. The client will usually cache it after that, so subsequent requests will be quicker.
Whatever event starts the loading of image should also make the loading indicator visible. The indicator is later hidden when the onload event of the view that holds the image is fired. The onload event is fired when that view attaches its resource.
Enjoy!