自定义类不在屏幕上显示组件Actionscript 3

时间:2011-06-10 12:20:48

标签: flash actionscript-3

我正在尝试使用AS3为flash创建自定义组件,但是当我创建我的类的实例并将其添加到舞台时,屏幕上不会显示任何内容。我似乎无法弄明白......

我所拥有的是一个扩展MovieClip的类,它包含一些textField组件,我为其设置文本然后调用addChild(tfn);但没什么......

任何帮助都非常感激。

以下是代码:

package com.utils {
    import flash.display.MovieClip;
    import flash.text.TextField;
    import flash.display.Loader;
    import fl.controls.Button;
    import flash.net.URLRequest;
    import flash.text.TextFormat;
    import flash.events.MouseEvent;
    import flash.events.Event;

public class LeaderBoardLoader extends MovieClip {

    // components
    public var txtPosition:TextField;
    public var thumbHolder:MovieClip;
    public var container:MovieClip;
    public var txtName:TextField;
    public var txtVotes:TextField;
    public var btnViewVid:Button;
    public var imgLoader:Loader;

    // text styling
    public var myFormat:TextFormat;  
    public var myFormat2:TextFormat;
    public var myFormat3:TextFormat;

    public function LeaderBoardLoader(position:String, imageURL:String, pers:String, votes:String, vidURL:String) 
    {
        txtPosition = new TextField();
        thumbHolder = new MovieClip();
        txtName = new TextField();
        txtVotes = new TextField();
        btnViewVid = new Button();
        container = new MovieClip();
        myFormat = new TextFormat();
        myFormat2 = new TextFormat();
        myFormat3 = new TextFormat();
        imgLoader = new Loader();
        trace("started");

        //Giving the format a hex decimal color code  
        myFormat.color = 0xFFFFFF;   
        //Adding some bigger text size  
        myFormat.size = 16;  
        //Giving the format a hex decimal color code  
        myFormat2.color = 0xFFFFFF;   
        //Adding some bigger text size  
        myFormat2.size = 11;  
        //Giving the format a hex decimal color code  
        myFormat3.color = 0xEF0000;   
        //Adding some bigger text size  
        myFormat3.size = 10;  
        trace("started");
        container.width = 500;
        container.height = 50;



        txtPosition.x = 0;
        txtPosition.y = 0;
        txtPosition.text = position + ".";
        txtPosition.setTextFormat(myFormat);
        trace("started1");
        //imgLoader.load(new URLRequest(imageURL));
        imgLoader.width = 60;
        imgLoader.height = 60;
        thumbHolder.addChild(imgLoader);
        thumbHolder.x = 20;
        thumbHolder.y = 0;
        trace("started2");
        txtName.text = pers;
        txtName.x = 100;
        txtName.y = 10;
        txtName.setTextFormat(myFormat2);
        trace("started3");
        txtVotes.text = votes;
        txtVotes.x = 100;
        txtVotes.y = 20;
        txtVotes.setTextFormat(myFormat2);
        trace("started4");
        btnViewVid.textField.text = "VIEW VIDEO";
        btnViewVid.textField.setTextFormat(myFormat3);
        btnViewVid.x = 200;
        btnViewVid.y = 20;
        btnViewVid.addEventListener(MouseEvent.CLICK, viewVideo);
        addChild(txtPosition);
        addChild(thumbHolder);
        addChild(txtName);
        addChild(txtVotes);
        addChild(btnViewVid);


    }


    function viewVideo(evt:MouseEvent):void
    {
        trace("hulo light");            

    }




}

}

所有跟踪并且没有编译器错误....

1 个答案:

答案 0 :(得分:2)

在您的主课程中:

var displayTest:MovieClip = new LeaderBoardLoader("tavu", "bump.jpg", "kevin", "12");
addChild(displayTest);