I need some help with Positions of buttons in AS3. Same as before Topic, i made a IRC client with AS3, but when a user join a channel, there will be a button added, but if there is already a button and the user join new channel on IRC, there will be added new button also, this for every channel that a user does join, but It should to be positioned after the last button (side by side). Same for if a user join more channels. How can i do this on best way with x and y positions?
This is my code for now:
function onChannelButton(channel)
{
var test:MovieClip = new MovieClip();
var btn:Button;
for(var j:int = 0; j < btn.length; j++) {
btn = new Button();
btn.name = "btn";
btn.label = channel;
btn.width = 90;
btn.x = 120;
btn.y = 487.25;
test.addChild(btn);
}
addChild(test);
}
Hopefully, u can help me! Thanks!
Try this:
const PADDING:uint = 10;
const NUM_BUTTONS:uint = 10;
onChannelButton();
function onChannelButton():void {
var test:Sprite = new Sprite();
var btn:Button;
//NUM_BUTTONS or btn.length ? (Don't know about your Button class
for (var i:int = 0; i < NUM_BUTTONS; i++)
{
btn = new Button();
btn.name = "btn";
btn.width = 90;
btn.x = (btn.width + PADDING) * i;
test.addChild(btn);
}
addChild(test);
}