Image Flex 4.6通过单个更新周期以编程方式将图像添加到视图的元素列表中

Image Flex 4.6通过单个更新周期以编程方式将图像添加到视图的元素列表中,image,apache-flex,mobile,flex4,flex4.5,Image,Apache Flex,Mobile,Flex4,Flex4.5,我想在运行时将图像添加到s:View中。但是,我需要在覆盖数据时添加它们,以优化视图的外观。但是,我的容器s:View尚未添加到显示列表或创建,我不确定,因为我很难理解生命周期,而且我是Flex 4.6的新手。无论如何,容器尚未实例化。那么,如何将图像添加到元素列表中,以便在创建视图时将其作为元素添加 基本上与在mxml上编写它们时发生的方式相同 谢谢, Dave你可以这样做: var v:View = new View(); v.layout = new VerticalLayout(); v

我想在运行时将图像添加到s:View中。但是,我需要在覆盖数据时添加它们,以优化视图的外观。但是,我的容器s:View尚未添加到显示列表或创建,我不确定,因为我很难理解生命周期,而且我是Flex 4.6的新手。无论如何,容器尚未实例化。那么,如何将图像添加到元素列表中,以便在创建视图时将其作为元素添加

基本上与在mxml上编写它们时发生的方式相同

谢谢,
Dave

你可以这样做:

var v:View = new View();
v.layout = new VerticalLayout();
var img:Image = new Image();
img.source = "/path/to/image1";
v.addElement(img);
img = new Image();
img.source = "/path/to/image2";
v.addElement(img);
img = new Image();
img.source = "/path/to/image3";
v.addElement(img);
this.addElement(v);

我必须在createChildren上添加元素,而不是覆盖数据

 override public function set data(value:Object):void
 {
   super.data = value;

   if(value == null)
       {
           //initialize the data with the images I need to cache
       }
}

override protected function createChildren():void
{
super.createChildren();
if(container && definition)//These are the components I need to have instanciated
{
       //I then use the cached Images I initialized on the override of data
}
}

谢谢,布莱恩,但那不是我需要的。请看,我的视图为空,因为我的问题是在重写数据时,还没有调用createChildren。我知道怎么做了。我会回答我自己的问题来结束它。