Solved

Positioning a dynamically sized movieclip dynamically as3

Posted on 2011-09-06
7
462 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
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

I have been doing hardcore actionscripting for some time; and needless to say I have faced a lot of problems in just understanding others' code rather than understanding what the code executes. A programmer's life can become hell when there are a lo…
While working over numerous projects I often had the requirement for doing a screen capture in AS3.0. Unfortunately I found no "ready made" solutions in google search that suited my requirements. But I did come across some great resources which help…
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.
The goal of the tutorial is to teach the user what frame rate is, how to control it and what effect it has on the video.

747 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now