ghostdog
05-23-2006, 02:30 AM
I have a view containing images. the images are created according to paths specified in a dataset, in the following way:
<view datapath="..." >
<image src="$path{'@img_path'}" ... />
now, I want to switch the dataset in runtime in
order to change the images in the view. everything works OK until I try to switch before the current set of images finished downloading. in that case no images are shown at all. I tried doing 'unload' on the images before switching but this does not seem to help. any suggestions?
here is some code to demonstrate the problem:
<canvas debug="true">
<dataset name="imgdata_1">
<images>
<img id="a1" imgpath="img_1/a.jpg" />
<img id="a2" imgpath="img_1/b.jpg" />
<img id="a3" imgpath="img_1/c.jpg" />
</images>
</dataset>
<dataset name="imgdata_2">
<images>
<img id="b1" imgpath="img_2/a.jpg" />
<img id="b2" imgpath="img_2/b.jpg" />
<img id="b3" imgpath="img_2/c.jpg" />
</images>
</dataset>
<attribute name="curdata" type="number" value="1"/>
<method event="oninit">
imgView.setAttribute("datapath", "imgdata_1:/images/img");
// Debug.write("init!");
</method>
<!-- a button to switch the image set -->
<button y="15" x="150" onclick="changeSet()">Switch set
<method name="changeSet">
Debug.write("change from: " + canvas.getAttribute("curdata"));
if(canvas.getAttribute("curdata") == 1) {
canvas.setAttribute("curdata", 2);
imgView.setAttribute("datapath", "imgdata_2:/images/img");
}
else {
canvas.setAttribute("curdata", 1);
imgView.setAttribute("datapath", "imgdata_1:/images/img");
}
</method>
</button>
<view id="mainView" width="400" height="600" y="50" x="150">
<simplelayout axis="y" spacing="10"/>
<view id="imgView"
bgcolor="#e8f2e8">
<image src="$path{'@imgpath'}" stretches="both">
<method event="onload" >
Debug.write("loaded!!!");
</method>
</image>
</view>
</view>
</canvas>
thanks in advance,
Amir
<view datapath="..." >
<image src="$path{'@img_path'}" ... />
now, I want to switch the dataset in runtime in
order to change the images in the view. everything works OK until I try to switch before the current set of images finished downloading. in that case no images are shown at all. I tried doing 'unload' on the images before switching but this does not seem to help. any suggestions?
here is some code to demonstrate the problem:
<canvas debug="true">
<dataset name="imgdata_1">
<images>
<img id="a1" imgpath="img_1/a.jpg" />
<img id="a2" imgpath="img_1/b.jpg" />
<img id="a3" imgpath="img_1/c.jpg" />
</images>
</dataset>
<dataset name="imgdata_2">
<images>
<img id="b1" imgpath="img_2/a.jpg" />
<img id="b2" imgpath="img_2/b.jpg" />
<img id="b3" imgpath="img_2/c.jpg" />
</images>
</dataset>
<attribute name="curdata" type="number" value="1"/>
<method event="oninit">
imgView.setAttribute("datapath", "imgdata_1:/images/img");
// Debug.write("init!");
</method>
<!-- a button to switch the image set -->
<button y="15" x="150" onclick="changeSet()">Switch set
<method name="changeSet">
Debug.write("change from: " + canvas.getAttribute("curdata"));
if(canvas.getAttribute("curdata") == 1) {
canvas.setAttribute("curdata", 2);
imgView.setAttribute("datapath", "imgdata_2:/images/img");
}
else {
canvas.setAttribute("curdata", 1);
imgView.setAttribute("datapath", "imgdata_1:/images/img");
}
</method>
</button>
<view id="mainView" width="400" height="600" y="50" x="150">
<simplelayout axis="y" spacing="10"/>
<view id="imgView"
bgcolor="#e8f2e8">
<image src="$path{'@imgpath'}" stretches="both">
<method event="onload" >
Debug.write("loaded!!!");
</method>
</image>
</view>
</view>
</canvas>
thanks in advance,
Amir