Solved

Positioning a dynamically sized movieclip dynamically as3

Posted on 2011-09-06
7
464 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
air/as3 : is there a way to simulate TouchEvents? 1 404
FLV versus SWF 11 270
Adobe Flash Player - PPAPI plugin 6 538
Flash player updates using SCCM 2012 and SCUP 2011 3 391
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…
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 live broadcast using Flash Media Live Encoder and connecting it to YouTube to broadcast. Log into your Youtube account, choose live stream settings, start live stream from Flash Media Live Enc…
The goal of the tutorial is to teach the user how to set there setting in Adobe Flash Media Live Encoder and YouTube for optimal video and audio quality.

895 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

21 Experts available now in Live!

Get 1:1 Help Now