actionscript 3 - Dynamically generated MXML data doesn't get rendered -
so have requirement display dynamically generated data in view.
for this, idea create mxml file , use object. fill data in ibject , use addchild display it. after adding data. dynamically generated mxml file doesn't gets displayed.
code
buytogethergrid.mxml
<?xml version="1.0" encoding="utf-8"?> <mx:box xmlns:mx="http://www.adobe.com/2006/mxml" width="80" height="60" xmlns:image="org.commodity.detail.image.*"> <mx:hbox> <image:imagebox id="buytogetherimg"></image:imagebox> <mx:vbox id="textinfo"> <mx:box id="commonnamebox"> <mx:label id="commonname"> </mx:label> </mx:box> <mx:box id="commonpricebox"> <mx:label id="commonprice"> </mx:label> </mx:box> </mx:vbox> </mx:hbox> <mx:script> <![cdata[ public function creategrid():void{ this.buytogetherimg = new imagebox(); this.commonname = new label(); this.commonprice = new label(); } ]]> </mx:script> </mx:box>
this mxml file. idea create object of mxml object. add data buytogetherimg, commonname, commonprice , use addchild
part set data
<mx:hbox id="buytogetherbox" width="100%" bordercolor="black"> </mx:hbox>
the upper hbox container keep generated object
var buytogetherbox : buytogethergrid = new buytogethergrid(); buytogetherbox.creategrid(); each(var item:cmlistitem in commod.items){ if(item.dataformat == 2){ buytogetherbox.buytogetherimg.imgdata = item.value imagedata; } else if(item.dataformat == 0){ buytogetherbox.commonname.text = item.value.tostring(); } else if(item.dataformat == 3){ buytogetherbox.commonprice.text = stringutil.numtostrprice(item.value number); } } this.buytogetherbox.addchild(buytogetherbox); }
the code check conditions , add data. buytogetherbox not visible. if try like
this.buytogetherbox.addchild(buytogetherbox.buytogetherimg);
then can see image in h:box.
i pretty new flex. may have missed something
you leaving statically created instances of label , image control unused , creating new instances instead. basically, entire creategrid()
function unnecessary. have controls created in mxml. use them creating new instances.
var grid:buytogethergrid = new buytogethergrid(); grid.addeventlistener(flexevent.creation_complete, this.grid_creationcompletehandler);
elsewhere in same class...
private function grid_creationcompletehandler(event:flexevent):void { // set properties here }
Comments
Post a Comment