开发者

My VBox doesn't add child if all the objects' height over the VBox's height

I have a VBox with fixed width and height, and I add image objects with fixed width and height. I find that if my objects' height exceed the VBox's height, it doesn't show the object. I tried validateNow(), but it doesn't work. The object is added, but VBox just doesn't display it, so it leaves a blank with a same height as my other object. My codes are like:

This is the added object class:

public class ListElement extends Canvas
{
[Embed(source="/assets/friendlist/btn2.png")]private var namereckImg:Class;
[Embed(source="/assets/friendlist/btn2.png")]private var joinbtnImg:Class;

public var nameReck:Image;
public var joinBtnIcon:Image;
public var Name:Label;

        public function ListElement(id:String,name:String)
    {

        ID=id;

        this.width=223;
        this.height=30;

        Name=new Label();

        nameReck=new Image();
        nameReck.source=namereckImg;
        nameReck.x=30;
        nameReck.y=6;
        this.addChild(nameReck);

         Name.text=name;
        Name.x=30;Name.y=6;
        this.addChild(Name);


        joinBtnIcon=new Image();
        开发者_开发知识库joinBtnIcon.source=joinbtnImg;
        joinBtnIcon.x=150;
        joinBtnIcon.y=33;
        this.addChild(joinBtnIcon);

        //this.validateNow();
    }
}

And the function to add the object is like:`

public function addFriend():void{
        var id:String="MY_ID";
var name:String="MY_NAME";
var le:ListElement=new ListElement(id,name);
        /*le.addEventListener(MouseEvent.CLICK,onClickElement);
        le.addEventListener(FLEvent.OPENGIFTOPTION, onDpOpenGiftOption);
        le.addEventListener(FLEvent.SENDMSG, onDpSendMsg);
        le.addEventListener(LobbyEvent.SHOWCONFIRMBOX, onDpShowConfirmBox);
        le.addEventListener(FLEvent.OPENSTA, onDpOpenSta);
        le.addEventListener(FLEvent.CLOSESTA, onDpCloseSta);*/

        vbox.addChild(le);

    }


Just solved the problem. I found the problem only happen if the vbox isn't in the container(the canvas), once I add it in the canvas before adding the child into it, it shows.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜