Flex 中addChild没法显示元素
Flex 中addChild无法显示元素
创建Flex项目,请问下面的代码执行后,label对象为什么无法显示出来?就算将label替换为Sprite,Sprite里画线条,也一样无法显示?
------解决方案--------------------
la.width=100;
la.height=100;加上就OK
------解决方案--------------------
没有设置线条样式。
创建Flex项目,请问下面的代码执行后,label对象为什么无法显示出来?就算将label替换为Sprite,Sprite里画线条,也一样无法显示?
- JScript code
<?xml version="1.0" encoding="utf-8"?> <s:Group xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark" xmlns:mx="library://ns.adobe.com/flex/mx" width="400" height="300"> <fx:Script> <![CDATA[ import mx.controls.Label; import mx.core.*; //显示网格线 //width : 地图总宽度 //height : 地图总高度 //size : 单元格尺寸 public function ShowGrid(xlen : int,ylen : int,size : int) : void { var sp : Sprite = new Sprite(); var comp: UIComponent = new UIComponent(); comp.addChild(sp); var la : Label = new Label(); la.text = "demo"; comp.addChild(la); la.x = 50; la.y = 50; this.addElement(comp); } ]]> </fx:Script> <fx:Declarations> <!-- 将非可视元素(例如服务、值对象)放在此处 --> </fx:Declarations> </s:Group>
------解决方案--------------------
la.width=100;
la.height=100;加上就OK
------解决方案--------------------
没有设置线条样式。