PDA

View Full Version : Dynamically changing resource for a view


sandman
02-18-2003, 01:46 PM
Hi,

Is it possible to change the "resource" attribute of a view? I tried getAttribute()/setAttribute without success. getAttribute('resource') returns nothing and setAttribute('resource','<some image>') has no effect. Code snippet would help.

thanks,
Sandeep.

antun
02-18-2003, 03:04 PM
Absolutely! There's two ways:

1) Use setResource to set it to a named resource that was declared in the app using <resource>. (a.gif below).

2) Use setSource to request that graphic over HTTP when setSource() is called. (b.gif below).


<canvas>
<resource name="myA" src="a.gif" />

<simplelayout axis="y" spacing="5" />

<view id="myView" x="35" y="35" />

<button label="set to A" onclick="myView.setResource( 'myA' );" />
<button label="set to B" onclick="myView.setSource( 'b.gif' );" />
</canvas>

Take care,

Antun

sandman
02-18-2003, 03:21 PM
Hi Antun,

I have created a subclass of view and would like to get the resource from an instance of this class and set this in another view. I have to deal with a lot of images which are dynamically read. Therefore, I don't have the option of declaring these resources via the resource tag.

Will something like this work? I need to somehow get the values of the resource attribute from one view and set it in another view.

thanks,
Sandeep.

antun
02-18-2003, 04:46 PM
Hey Sandeep

You can't really get a view's resource. In your case, since you're setting it using setSource, you can set an attribute of the view/class to the string of the resource when you set the source:-


<canvas>
<simplelayout axis="y" spacing="5" />
<view id="myView" x="35" y="35" />
<button label="set to B" onclick="myView.setSource( 'b.gif' ); myView.myResource = 'b.gif';" />
</canvas>


-Antun

arina
01-28-2005, 04:18 AM
Antun!

It doesn't work for me:( Why? This is the code example. Only second button loads image. But I cann't define <resource> on canvas, it's source loads dynamically from dataset.


<canvas layout="axis:y;spacing:25;inset:25;">

<resource name="bird" src="../resources/bird.jpg"/>

<button onclick="parent.myView.setSource('../resources/bird.jpg');" text="setSource" x="35"/>
<button onclick="parent.myView.setResource('bird');" text="setResource" x="35"/>
<view name="myView" x="35"/>

</canvas>


Thank you for any help