PDA

View Full Version : Once/Always OnInit/OnData


Salicar
09-06-2006, 02:18 AM
Hi all,

I hope you can help me with this issue it has been causing me many a frustrating hour.

I am trying to do the following:

Bind an image dynamically to a view where the url is formed from a datapath provided to the binding.

<canvas height="100%" width="100%" title="Testing Site">
<!--
statedataset.xml
<states>
<state portal_count_flg="Y" state_id="1"/>
<state portal_count_flg="Y" state_id="3"/>
<state portal_count_flg="Y" state_id="4"/>
<state portal_count_flg="Y" state_id="5"/>
</states>
-->

<dataset name="statedataset" type="http" request="false" src="./statedataset.xml">
<handler name="ondata">
Debug.write('ondata flicker');
</handler>
</dataset>

<handler name="oninit">
canvas.tick();
</handler>

<method name="tick">
this.refreshDelegate = new LzDelegate( this, "tickprogress" );
LzTimer.addTimer( this.refreshDelegate, 10000);
</method>

<method name="tickprogress">
statedataset.doRequest();
this.tick()
</method>

<class name="testing">
<simplelayout axis="x" spacing="5"/>
<view datapath="state[@portal_count_flg='Y']" source="${'resources/images/small_state_' + this.datapath.xpathQuery('@state_id') + '_icon.png'}"/>
</class>

<testing>
<datapath xpath="statedataset:/states" pooling="true"/>
</testing>
</canvas>

As you can see above it willl cause a flicker on each ondata event from the dataset. This is because the source paramater is rebound upon each doRequest call. Fair enough what i expected.

So by switching to using source="$once it only gets set once. However the results here are dependant upon the dataset being retrieved quicker than the oninit event triggering!

Ideally i want an ondata event which only triggers once. I can get by this by putting an If statement into the ondata but that it hardly ideal.

Should i be using initstage somehow?

Please help really struggling with this minor issue.

Regards,

Richard

jstretch
09-06-2006, 06:22 AM
I'm trying to figure this out still, help me understand: You only want to fire off the ondata event once, yet you have a loop via delegate that calls the doRequest() method every 10 seconds? What is the loop for?

Salicar
09-06-2006, 06:36 AM
hi sorry if me explanation is poor.

the delegate event is for a timed refresh of the dataset. so a user can see changes to the dataset frequently.

however by performing this refresh the resource is updated. which causes a flicker. so how can i make it so that i set the resource attribute up only once after the dataset has finished being created, but then still allow the data itself to refresh.

jstretch
09-06-2006, 07:04 AM
One more question: Do you ever intend to change the images once they are loaded the first time? Or will they also be updated occasionally?

Salicar
09-06-2006, 07:13 AM
just the once for the icon

jstretch
09-06-2006, 07:17 AM
Using initstage="defer" wont help because the source is evaluated onconstruct, before init().

Writing an if statement in the ondata will be taxing.

Easiet way I can think of is to split the image data into a seperate dataset... a seperate dataset doRequest() specifically for the images. Is this possible? To keep things linear you could call the tick() method from the ondata event of this new dataset.

Salicar
09-06-2006, 07:26 AM
yes that is probably the only simple way to ideally do this. at the moment i have put in the IF statement workaround. but i think holding another dataset may in fact be lighter weight than the CPU cycles i am eating on the IF statement.

thanks for your help.