Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Dynamic Text Alignment

Guest
May 11, 2010 May 11, 2010

Hello everybody.... well my question is ... How I can align a dynamic text loading xml file?

My code on Actionscript and XML is :

XML code:

It load the halls with text only....

<halls>
    <hall>Congress A </hall>
    <hall>Congress B</hall>
    <hall>Congress C</hall>
    <hall></hall>
    <hall></hall>
    <hall></hall>
    <hall></hall>
    <hall></hall>
    <hall></hall>
    <hall></hall>               
</halls>

AS code:

var urlLDR:URLLoader=new URLLoader();

urlLDR.addEventListener(Event.COMPLETE,f);

urlLDR.load(new URLRequest("hallsXML.xml"));

function f(e:Event) {

    var xml:XML =new XML(urlLDR.data);

    TXTvHall.text = "";

    for(var i:uint=0;i<xml.hall.length();i++){

        TXTvHall.appendText(xml.hall+"\n");

    }

}

The result of my flash is the next  in the dynamic text... so as you can see it doesnt appear aligned in the center..

How can I do that?

Untitled-1.jpg

TOPICS
ActionScript
2.5K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 11, 2010 May 11, 2010

center your textfield and assign its align property to "center".

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
May 11, 2010 May 11, 2010

Not sure what we're supposed to be looking for? Is your text field set to center? In the Properties panel in the Paragraph section you can choose center.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
May 11, 2010 May 11, 2010

the dynamic is set on center alignment... but the loeaded xml file is not... i mean... if i only have one hall text.. it look like this:

Untitled-1.jpg

so i want to appear on the middle of the dynamic ....

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
May 11, 2010 May 11, 2010

No idea what you are showing with these images... what is not centered???


Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
May 11, 2010 May 11, 2010

dmennenoh wrote:

No idea what you are showing with these images... what is not centered???


I think he meant to say "verticaly aligned"... now it's just horizontaly aligned.

I didn't read all the topic but it shouldn't be difficult to do so.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 11, 2010 May 11, 2010

you want vertical alignment?  if so, assign autoSize to "center" and subtract your textfield's height from the display region height and divide that difference by two.  assign your textfield's y property to that quotient.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
May 11, 2010 May 11, 2010

yes i want vertical alignment... where i need to code... on AS or XML?... and wich will be the code

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 11, 2010 May 11, 2010

assign autoSize to "center" and  subtract your textfield's height from the display region height and  divide that difference by two.  assign your textfield's y property to  that quotient.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
May 11, 2010 May 11, 2010

ok I assigned autoSize to "center" and  subtract text field -dynamic text- height (405.85) from  the display region height (1024) and  divide that difference by two (309.7).  Also i assigned  that quotient to y property.

So I encode like this on my AS file:

var urlLDR:URLLoader=new URLLoader();
urlLDR.addEventListener(Event.COMPLETE,f);
urlLDR.load(new URLRequest("hallsXML.xml"));

function f(e:Event) {

    var xml:XML =new XML(urlLDR.data);
    TXThall.autoSize = "center";
    TXThall.y = 309.7;
    TXThall.text = "";
    for(var i:uint=0;i<xml.hall.length();i++){

        TXTHall.appendText(xml.hall+"\n");
    }

}

but it doesnt work... It just positions the  first event in the 'y' coordinate (309.7) and the others down below not aligned vertically... and always the first event in that y position.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 11, 2010 May 11, 2010

use:


var urlLDR:URLLoader=new URLLoader();
urlLDR.addEventListener(Event.COMPLETE,f);
urlLDR.load(new URLRequest("hallsXML.xml"));

function f(e:Event) {

    var xml:XML =new XML(urlLDR.data);
    TXThall.autoSize = "center";
    TXThall.text = "";
    for(var i:uint=0;i<xml.hall.length();i++){

        TXTHall.appendText(xml.hall+"\n");
    }

TXThall.y=(TXTHall.height-stage.stageHeight)/2;


}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
May 11, 2010 May 11, 2010

OK... I copy and paste as same you wrote... and its not showing nothing....

any ideas??

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
May 12, 2010 May 12, 2010

kglad made a booboo...

TXThall.y=(TXTHall.height-stage.stageHeight)/2;

That line should be:

TXThall.y=Math.floor((stage.stageHeight - TXTHall.textHeight) / 2);

I like to use Math.floor to round to an integer so you don't put text on a fractional pixel - which can make it blurry. I also like to use textHeight on text fields just to be sure you don't use any extra white space in the field.


Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
May 12, 2010 May 12, 2010
LATEST

I change that line but is the same result....

If I have one event it look like this:

1.jpg

and if I fill all events look like this:

2.jpg

as you can see it doesnt align vertical....its the same alignment on the two images.... here is my code again...

var urlLDR:URLLoader=new URLLoader();
urlLDR.addEventListener(Event.COMPLETE,f);
urlLDR.load(new URLRequest("hallsXML.xml"));

function f(e:Event) {

    var xml:XML =new XML(urlLDR.data);
    TXThall.autoSize = "center";
    TXThall.text = "";
    for(var i:uint=0;i<xml.hall.length();i++){

        TXThall.appendText(xml.hall+"\n");
    }

TXThall.y= Math.floor((stage.stageHeight - TXThasll.textHeight) / 2);


}

My page size of the project is 768 * 1024 and the position & size of the dynamic text is X: 384.0    Y: 332.5  W: 664.0    H: 405.9...

I dont know if it helps that data....

Thanks for responding and I hope you can help me figure out this...

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines