Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 478
  • Last Modified:

Positioning a dynamically sized movieclip dynamically as3

I have a simple navigation structure (nextFrame/prevFrame) and a label component I'm using as a sort of closed captioning text box.  Each keyframe tells the label component what the text should be and the label component re-sizes itself accordingly.

I have a show/hide button which moves the text up (show) or down (hide):

function textUp():void
{	
	var yPos:int;
	yPos = 160 - lb.height;
	TweenLite.to(captions.lb, .5, {y:yPos, ease:Expo.easeOut});
}
function textDown():void
{
	textShowing=false;
	TweenLite.to(lb, .5, {y:160, ease:Expo.easeOut});
}

Open in new window


This is all easy enough.  The issue I have is if you have the captions/label component showing and navigate to the next frame, the text changes and the label component resizes, but of course it's then not positioned correctly if/when the component is re-sized with different text.  I guess because not only is the component registration point in the upper left but when additional lines are added/removed, it's re-sized from the bottom.

How can I get this component's y position to change correctly?


0
moglie
Asked:
moglie
  • 3
  • 2
  • 2
1 Solution
 
moagriusCommented:
unless you have manually changed the registration point, it will always been top-left.

additional text will increase the height, but the "y" will always be top left.

can you describe the setup a little more, or provided a simplified example of the problem you're describing?  is the caption stuck to the bottom of the stage, and sliding beyond the stage bounds to hide?

my best guess at this point - without fully understanding the setup - is to reposition the caption immediately after the text is updated as well, based on the recomputed height.
0
 
moglieAuthor Commented:
Attached is a very simplified version.  If you just show the caption/label component and then navigate forward and back you'll see what I'm talking about.  If you click show and then click hide before you navigate to the next page, there's no problem.  2 6 1

The first "page" has 2 lines of text.  The second has 6 lines and the third has 1 line of text but the label's y doesn't change.
sample.zip
0
 
moagriusCommented:
so you want to position based on the bottom - you want the bottom of the label component to always be the same.

each time you assign myLabel.text, use this:

myLabel.y = 372 - myLabel.textField.textHeight;
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
dgofmanCommented:
Replcace you funtions by my code it will fix your problem

function showTxt(event:MouseEvent):void{
      myLabel.visible = true;
      myLabel.y = showIt.y - myLabel.height;
}
function hideTxt(event:MouseEvent):void{
      myLabel.visible = false;
}
0
 
dgofmanCommented:
I improved my code check FLA file

myLabel.addEventListener(ComponentEvent.RESIZE, onTextResize);
function onTextResize(event:ComponentEvent):void{
      myLabel.y = showIt.y - myLabel.height;
};
 
function bk(event:MouseEvent):void{
      prevFrame();
};

function fwd(event:MouseEvent):void{
      nextFrame();
};

function showTxt(event:MouseEvent):void{
      myLabel.visible = true;
};

function hideTxt(event:MouseEvent):void{
      myLabel.visible = false;
};
sample.swf
sample.fla
0
 
dgofmanCommented:
You may get problem executing SWF file on the local drive (without debuging from CS4) in this case create HTML file by selecting File->Publish

or

remove your mask what cover your myLabel component
0
 
moglieAuthor Commented:
I got this to work with a few more additions.  Thanks.
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

  • 3
  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now