I created a box in paint and loaded it onto sprite using
[Embed(source="Colbox.png")]
var Colbox:Class;
private var NBVar:Bitmap = new Colbox ();
Code.The code that sets the coordinates
txtFld.x = 100;
txtFld.y = 100;
txtFld.width = 300;
txtFld.height = 300;
txtFld.text开发者_运维百科 = "80";
NBVar.x = 80;
NBVar.y = 80;
addChild(NBVar);
addChild(txtFld);
However the number 80 does not appear in the middle of the colored box. Is there a easier method to achieve this with better accuracy ?
NBVar.x = (colored_box.width/2) - (NBVar.width/2);
NBVar.y = (colored_box.height/2) - (NBVar.height/2);
This code will give u the perfect centre, and the NBVar
should be the child of colored_box
.
精彩评论