I'm trying to create a custom component for flash using AS3, but when i create an instance of my class and add it to the stage nothing is displayed on the screen. I just can't seem to figure it out...
What I have is a class that extends MovieClip, and contains a couple textField components for which i set the text and then call addChild(tfn); but nothing...
Any help much appreciated.
Here's the code:
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;
开发者_如何学JAVA 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");
}
}
}
All the traces and no compiler errors....
In your Main class :
var displayTest:MovieClip = new LeaderBoardLoader("tavu", "bump.jpg", "kevin", "12");
addChild(displayTest);
精彩评论