我想使用AS3爲Flash創建自定義組件,但是當我創建我的類的實例並將其添加到舞臺時,屏幕上不顯示任何內容。我似乎無法弄清楚......在屏幕上不顯示組件的自定義類Actionscript 3
我所擁有的是一個擴展MovieClip的類,它包含幾個textField組件,爲此我設置文本然後調用addChild(tfn);但沒有...
任何幫助非常感激。
下面的代碼:
包com.utils { 進口的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");
}
}
}
所有的痕跡,沒有編譯器錯誤....
這可能不會解決它,但看過[這個問題](http://stackoverflow.com/questions/6298284/textformat-doesnt-do-anything)後,我想你想設置'defaultTextFormat'屬性手動而不是調用'setTextFormat' – 2011-06-10 12:52:41