Jump to content
Search Community

align text within another mc using liquidArea

jodiW test
Moderator Tag

Recommended Posts

hello, jack, et al

 

i have set up a simple bit of code to center a mask (mask_mc), some controls (cntrls_mc) for a mc (text_mc) and inside that the dynamic text field (text_mc.info_txt), which loads some xml text:

 

var txtBlock:LiquidArea = new LiquidArea(this, 0, 0, 1920, 1080);
txtBlock.preview = false;

txtBlock.attach(mask_mc, ScaleMode.NONE, AlignMode.CENTER, AlignMode.CENTER);
txtBlock.attach(text_mc, ScaleMode.NONE, AlignMode.CENTER, AlignMode.CENTER);
txtBlock.attach(cntrls_mc, ScaleMode.NONE, AlignMode.CENTER, AlignMode.CENTER);

the above works perfectly on my 1920x1080 project, but the text inside the text_mc is also centered both vertically and horizontally, so showing the middle of the text block

 

i then tried to add in this line to make the info_txt mc inside the text_mc align at the top instead:

 

txtBlock.attach(text_mc.info_txt, ScaleMode.NONE, AlignMode.CENTER, AlignMode.TOP);

but got this error:

 

The parent of the DisplayObject info_txt added to AutoFitArea instance12 doesn't share the same parent.

 

i'm sure i'm missing something really obvious, so any help would be greatly appreciated; thank you!

Link to comment
Share on other sites

You can't attach() nested objects - that wouldn't logically work (in the process of moving objects in the child, the bounds of the parent would change, and moving the parent to align it would change the bounds of the children, etc.). Basically, anything you attach() to a LiquidArea must share the same parent as the LiquidArea.

 

I'm a little confused about what you're trying to do exactly. If text_mc is centered properly and your info_txt is centered inside text_mc, wouldn't that mean it's centered as well? What am I missing? Feel free to post a screen capture or a sample FLA if you can't figure it out.

Link to comment
Share on other sites

hi jack

 

thanks for the fast reply; that does make sense

 

i have attached the fla and xml file in a zip - what is happening is everything works perfectly when the 3 lines from the previous post are commented out, but as soon as i uncomment them, the text appears but the top few lines are missing, and scrolling up does not bring that missing text back - very odd! thank you, jodi

Link to comment
Share on other sites

From what I can tell, it is doing what you asked - you center both the mask and the content that's getting masked (text_mc). Since text_mc is taller than the mask, centering them both on the stage results in the top and bottom of the text_mc getting chopped by the mask.

 

Or did I misunderstand?

Link to comment
Share on other sites

ok, so then if you mean that the dynamic text generates say 800 pixels of content in height, and the mask is static at 500, then there is essentially 150 pixels top and bottom that are hidden? and if that is the case, then would it be safe to say that i could only center this if there is no scrolling? thanks, jack

Link to comment
Share on other sites

The first part is correct, yes. As for the second part, I'm not sure I understand what you're asking. You can center it regardless of the size. LiquidArea is doing what you asked. If you want your text and the mask centered, your code looks correct. However, if you want your mask centered and the text to adjust accordingly, just do that - center the mask and then run code that places your text with its top edge wherever the centered mask ended up.

Link to comment
Share on other sites

ok, thanks again i will try and create some code that does what you are suggesting - that is indeed what i am trying to achieve (i'm not really a programmer so this stuff is a bit challenging)

no need to reply, jack; it's clear that your excellent classes do exactly what i've asked them to :)

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...