Flex4: How to add a child to spark Scroller in AS

2019-08-22 06:51发布

问题:

I want to convert the following code to ActionScript (mxml works fine):

<mx:Panel title="Some Title" width="400" height="300">
  <s:Scroller width="100%" height="100%"/>
    <mx:ColumnChart id="myChart" attribute="..." />

This doesn't work straight forward:

setupChart(); //setup myChart

var scroll:Scroller = new Scroller();
scroll.percentWidth = 100;
scroll.percentHeight = 100;
scroll.viewport = myChart;

回答1:

adding a group first works for me

setupChart();

var grp:Group = new Group();
grp.percentWidth = 100;
grp.percentHeight = 100;
grp.addElement( myChart );

var scroll:Scroller = new Scroller();
scroll.percentWidth = 100;
scroll.viewport = grp;