Problem with resize flex viewer template

3554
6
Jump to solution
12-09-2014 12:23 AM
WuYang
by
New Contributor II

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.

0 Kudos
1 Solution

Accepted Solutions
RobertScheitlin__GISP
MVP Emeritus

Wu,

  I dynamically change the size of my widgets at runtime using this code:

wTemplate.widgetWidth = wTemplate.width = 530;
wTemplate.widgetHeight = wTemplate.height = 335;

View solution in original post

0 Kudos
6 Replies
AnthonyGiles
Frequent Contributor

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

0 Kudos
WuYang
by
New Contributor II

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?

0 Kudos
AnthonyGiles
Frequent Contributor

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:

ArcGIS Viewer for Flex

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

0 Kudos
WuYang
by
New Contributor II

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.

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Wu,

  I dynamically change the size of my widgets at runtime using this code:

wTemplate.widgetWidth = wTemplate.width = 530;
wTemplate.widgetHeight = wTemplate.height = 335;
0 Kudos
WuYang
by
New Contributor II

hello Robert,

awesome, it works. thanks so much.

0 Kudos