Copy link to clipboard
Copied
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?
Copy link to clipboard
Copied
center your textfield and assign its align property to "center".
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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:
so i want to appear on the middle of the dynamic ....
Copy link to clipboard
Copied
No idea what you are showing with these images... what is not centered???
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
yes i want vertical alignment... where i need to code... on AS or XML?... and wich will be the code
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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;
}
Copy link to clipboard
Copied
OK... I copy and paste as same you wrote... and its not showing nothing....
any ideas??
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
I change that line but is the same result....
If I have one event it look like this:
and if I fill all events look like this:
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...
Find more inspiration, events, and resources on the new Adobe Community
Explore Now