Flex HBox从数据库中读取图片URL地址,然后动态加载该图片,设置其为HBox的背景图片。
//初始化界面 private function init():void //设置HBox属性 var bc:HBox =new HBox(); bc.id="borderContainer_"+subsList[i].subsId; bc.width=160; bc.height=90; bc.setStyle("backgroundSize","100%"); loadPic(bc,subsList[i].imgSrc);//加载图片,subsList[i].imgSrc为图片URL地址,如assets/images/1.png等 } //加载图片 public function loadPic(hBox:HBox,imgurl:String):void { var loader:Loader = new Loader(); loader.load(new URLRequest(imgurl)); loader.contentLoaderInfo.addEventListener(Event.COMPLETE,function(event:Event){hBox.setStyle("backgroundImage",imgurl);} );//添加监听事件,若图片加载完成,则设置HBox的背景图 }