Question

I want to add Images into a s:View on runtime. However, I need them to be added on override of the data to optimize the apearance of the view. However, my container, the s:View, is not yet added into the display list or created I am not sure since I have a hard time understand the lifecycle and I am new in Flex 4.6. Anyway, the container is not yet instanciated. So how do I add the Images to the Elements list so that when the View is created it adds them as elements.

Basically same way that it happens when you write them on the mxml.

Thanks, Dave

Was it helpful?

Solution 2

I had to add the elements not on override of data but on 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
}
}

OTHER TIPS

You could do something like this:

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);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top