Greetings,
In my flex viewer, I need to change the template size at runtime. Have found the previous thread but cannot ask question there.
I refer to the following link:
http://forums.esri.com/Thread.asp?c=158&f=2421&t=279252
I follow the steps advised by Robert as follows:
(1) added the line in IWidgetTemplate.as
function setResize(value1:Number, value2:Number):void;
(2) added the following code in the WidgetTemplate.as
public function setResize(nHeight:Number, nWidth:Number):void
{
this.height = nHeight;
wCanvas.height = nHeight;
this.width = nWidth;
wCanvas.width = nWidth - 40;
}
But I got the error:
access of undefined property wCanvas.
(3) add the following in mx:State in the mxml which I want to resize the template.
<mx:SetProperty target="{wCanvas}" name="height" value="{height}"/>
<mx:SetProperty target="{wCanvas}" name="width" value="{width - 40}"/>
But wherever I put the mx:state, It always return me:
<mx:state> is not allowed here.
I am not sure whether step (3) is correct, and where should I define wCanvas? or should I use wTemplate instead of wCanvas?
Or is it because the version is different (I use version 3.6).
Any idea? advice is appreciated.
Solved! Go to Solution.
Wu,
I dynamically change the size of my widgets at runtime using this code:
wTemplate.widgetWidth = wTemplate.width = 530; wTemplate.widgetHeight = wTemplate.height = 335;
Wu,
There is no reference to wCanvas in the later versions of the viewer, you should be able to change the size of the widget using the properties of wTemplate, add the following function:
public function setResize(nHeight:Number, nWidth:Number):void
{
wTemplate.height = nHeight;
wTemplate.width = nWidth;
}
then call the function from what ever action you want:
setResize(900,900)
Regards
Anthony
Hi Anthony,
Thanks a lot for the answer, seems new version is easier, but after I update the code, the template size never change. should I change the basewidget also?
EDIT: After I drag the template I can change the size. I use setResize at init(), is should resize when loading the template right?
Wu,
I am not sure what you are trying to achieve by setting the width and height in the init() function. Out of the box widgets can be resized in the main config file, by adding the width and height attributes to the widget tag:
e.g: <widget label="GeoRSS" url="widgets/GeoRSS/GeoRSSWidget.swf" config="widgets/GeoRSS/GeoRSSWidget.xml" width="350" height="300"/>
If you are creating your own widget then you can add the width and height attributes to the widgetTemplate tag:
<viewer:WidgetTemplate id="wTemplate" width="350" height="300" .....>
Regards
Anthony
Thank Anthony,
I have already set the width and height according to page you gave.
But I need to change every time because in my widget I need to load several images (the number of images will change each time).
I am thinking another approach, which use a auto scrollbar to the widget, but also cannot get what I want.
Wu,
I dynamically change the size of my widgets at runtime using this code:
wTemplate.widgetWidth = wTemplate.width = 530; wTemplate.widgetHeight = wTemplate.height = 335;
hello Robert,
awesome, it works. thanks so much.