Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Positioning a dynamically sized movieclip dynamically as3

Posted on 2011-09-06
7
Medium Priority
?
475 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
[X]
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
  • 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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 2000 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

This is a very simple example to help those of you who are still migrating from AS2 to AS3 understand the redesigned event model in AS3. In AS2.0, event functions (that is, the function to be performed when an event is fired) were stored as a pro…
I know the transition can be hard. We got used to the ease of use ActionScript 2 had, but honestly, it became problematic later on, especially if designers were involved in the project and found it easy to add code as they saw fit. So, this artic…
The goal of the tutorial is to teach the user how to use the auto adjust feature and what the different options do. When your video is not working right you can choose the auto adjust feature to help choose your settings.
The goal of the tutorial is to teach the user how to select which audio input to use. Once you have an audio input plugged into the laptop or computer, you will go into the audio input settings and choose which audio input you want to use.

722 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