Help with a dynamic text
Hey guys...
I have a little issue with 2 texts I am trying to have in my stage, having them resized depending on where the whole thing gets opened... one of them has always the same text and the other one changes all the time...
The problem I have is:
The first one: if it takes the width of the screen to resize it fits good, but in a small device it is too small to be read. If it takes the height of the screen, it doesnt fit ok on the width and you lose some of the words.
The second one: it starts with the right size and position... (when it is a 2 digits text) but after it gets 3 or more digits, if you re add the text in the screen it resizes and has the digits way smaler than before.
Here is the code:
public class PruebaMP extends Sprite
{
private var bg1:Loader;
private var nivel1pic:Loader;
private var nivel4pic:Loader;
private var play1:Loader;
private var fmat31:TextFormat;
private var fmat3:TextFormat;
private var count:int;
private var level:int;
private var lvlup:int;
private var updlvl:int;
private var instructivo:TextField;
private var score_text:TextField;
private var score_txt:TextField;
private var instructivo_holder:Sprite;
private var score_txt_holder:Sprite;
private var score_text_holder:Sprite;
public function PruebaMP()
{
this.stage.scaleMode = StageScaleMode.NO_SCALE;
this.stage.align = StageAlign.TOP_LEFT;
Multitouch.inputMode = MultitouchInputMode.GESTURE;
stage.addEventListener(TransformGestureEvent.GESTURE_SWIPE , onSwipe);
startGame();
}
private function startGame():void {
page1();
}
private function page1():void {
bg1= new Loader();
bg1.contentLoaderInfo.addEventListener(Event.COMPLETE, onComplete);
bg1.load(new URLRequest("back1.jpg"));
nivel1pic = new Loader();
nivel1pic.contentLoaderInfo.addEventListener(Event.COMPLETE, onComplete);
nivel1pic.load(new URLRequest("nivel1.jpg"));
nivel4pic = new Loader();
nivel4pic.contentLoaderInfo.addEventListener(Event.COMPLETE, onComplete);
nivel4pic.load(new URLRequest("nivel3.jpg"));
play1 = new Loader();
play1.contentLoaderInfo.addEventListener(Event.COMPLETE, onComplete);
play1.load(new URLRequest("play.png"));
play1.addEventListener(MouseEvent.CLICK, playGame);
fmat3 = new TextFormat();
fmat3.font = "CooperBlack";
fmat3.size = 20;
fmat3.color = "0x00FFFF";
fmat3.align = "center";
fmat3.bold = true;
fmat31 = new TextFormat();
fmat31.font = "CooperBlack";
fmat31.size = 30;
fmat31.color = "0x000000";
fmat31.align = "center";
fmat31.bold = true;
instructivo = new TextField();
instructivo.border = true;
instructivo.defaultTextFormat = fmat3;
instructivo.autoSize = TextFieldAutoSize.CENTER;
score_text = new TextField();
score_text.defaultTextFormat = fmat31;
score_text.autoSize = TextFieldAutoSize.LEFT;
score_txt = new TextField();
score_txt.defaultTextFormat = fmat31;
score_txt.autoSize = TextFieldAutoSize.LEFT;
instructivo_holder = new Sprite();
score_text_holder = new Sprite();
score_txt_holder = new Sprite();
addInst();
}
private function onComplete(e:Event):void {
bg1.width = stage.stageWidth;
bg1.height = stage.stageHeight;
bg1.x = 0;
bg1.y = 0;
nivel1pic.width = stage.stageWidth;
nivel1pic.height = stage.stageHeight;
nivel1pic.x = 0;
nivel1pic.y = 0;
nivel4pic.width = stage.stageWidth;
nivel4pic.height = stage.stageHeight;
nivel4pic.x = 0;
nivel4pic.y = 0;
play1.width = (stage.stageWidth * 0.25);
play1.height = (stage.stageHeight * 0.12);
play1.x = (stage.stageWidth * 0.34);
play1.y = (stage.stageHeight * 0.71);
}
private function addInst():void {
addChild(bg1);
instructivo_holder.addChild(instructivo);
addChild(play1);
instructivo.text="You are in the Far, Far West; where the one surviving was always the faster gunman... \n Press on the enemies to shoot at them, not allowing them to shoot at you. Be careful, they are going to be faster every time you level up. \n \n Get excited with this amazing 20 levels game where each enemy killed gives you 10 points and each level they get faster. \n You have a three loads of dynamite and 5 lives to do so. \n DO YOU HAVE WHAT IS NEEDED TO FREE THE TOWN?";
stage.addChild(instructivo_holder);
instructivo_holder.width = (stage.stageWidth * 0.90);
//instructivo_holder.height = (stage.stageHeight * 0.70);
instructivo_holder.scaleY = instructivo_holder.scaleX;
instructivo_holder.x = (stage.stageWidth / 2.2);
instructivo_holder.y = (stage.stageHeight * 0.01);
}
private function playGame():void {
if (!level){level = 1;}
lvlup = 200;
updlvl = (lvlup * level);
if (!count){count = 0;}
UpdateFields();
if (level == 1) level1();
if (level == 4) level4();
//here I have the other functions that add the score and make the game works... then I have:
}
private function level1():void {
addChild(nivel1pic);
addingTexts();
}
private function level4():void {
removerViejoNivel();
addChild(nivel4pic);
addingTexts();
}
private function removerViejoNivel():void {
if (score_text.parent) {score_text.parent.removeChild(score_text);}
if (score_text_holder.parent) {score_text_holder.parent.removeChild(score_text_holder);}
if (nivel1pic.parent) {nivel1pic.parent.removeChild(nivel1pic);}
}
private function UpdateFields():void {
score_txt.text = String(count);
}
//it also has some other functions and when the score is 200, the level changes to 2, at 400 it changes to 3, at 600 it changes to 4, etc
private function addingTexts():void {
score_text_holder.addChild(score_text);
score_txt_holder.addChild(score_txt);
score_text.text="Score";
score_txt.text = String(count);
stage.addChild(score_text_holder);
stage.addChild(score_txt_holder);
score_text_holder.width = (stage.stageWidth * 0.08);
score_text_holder.scaleY = score_text_holder.scaleX;
score_text_holder.x = (stage.stageWidth / 4.5);
score_text_holder.y = (stage.stageHeight * 0.04);
score_txt_holder.width = (stage.stageWidth * 0.017);
score_txt_holder.scaleY = score_txt_holder.scaleX;
score_txt_holder.x = (stage.stageWidth / 3.2);
score_txt_holder.y = (stage.stageHeight * 0.04);
}
}
How can I make them work properly?
Thanks and happy new year to all of you!