Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Positioning a dynamically sized movieclip dynamically as3

Posted on 2011-09-06
7
471 Views
Last Modified: 2013-11-11
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
Comment
Question by:moglie
  • 3
  • 2
  • 2
7 Comments
 
LVL 19

Expert Comment

by:moagrius
ID: 36491535
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
 

Author Comment

by:moglie
ID: 36491849
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
 
LVL 19

Expert Comment

by:moagrius
ID: 36491929
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
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
LVL 29

Expert Comment

by:dgofman
ID: 36493103
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
 
LVL 29

Accepted Solution

by:
dgofman earned 500 total points
ID: 36493145
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
 
LVL 29

Expert Comment

by:dgofman
ID: 36493239
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
 

Author Closing Comment

by:moglie
ID: 36540040
I got this to work with a few more additions.  Thanks.
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Download slideshow or picture elements 16 438
Flash Player White Screen Facebook 5 775
free flash maker 5 216
PDF: Display my cards game? 8 124
Sometimes you know that one object has a specific child in it, but you can't find the child. This happened to me when I was trying to code some actionScript to make a toolbar work with its embedded buttons.  My partner had created the toolbar usi…
There are times in your Flash CS4 application when you want more than a simple pointer or a hand, and it's hard to find an ideal walk-through to tell you what to do.  I spent a few days recently learning my way around making custom cursors in Flash,…
The goal of the tutorial is to teach the user how to how to load their YouTube profile onto Flash Media Live Encoder.
The goal of the tutorial is to teach the user how to how to record live broadcast.

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question