1
votes

I'm relatively new to Actionscript and Flash, but have a great deal of experience in a Microsoft environment, so what I'm trying to do would just work in .NET but something is fundamentally different in Flash and I'm not getting it I'm afraid.

The problem I'm having is that I want to add a library object ( in this case, a simple rectangle ) to my stage, creating it dynamically using ActionScript 3.

If I drag the object to the stage, it appears as expected with a height of 33px and width 152px

If I instantiate is using ActionScript like so:

var rect1:myObject = new myObject() ;
rect1.x = 0 ;
rect1.y = 0 ;
addChild ( rect1 ); 

It appears as expected

I now want to place another directly below is, so I write:

var rect2:myObject = new myObject() ;
rect2.x = 0 ;
rect2.y = rect1.height ;
addChild ( rect2 ); 

I expect it to be aligned with the first object, touching its lower edge, but it appears way below the first object ( debug reports rect1.height is actually set to 106.5! )

If I hard code rect2.y = 33, it appears as expected, touching the first object

What on earth is happening here. I've looked at scaleY for the stage but it is just set to 1. I've also looked at the stage.height (273.9) and stage.stageHeight (768) to see if there's a correlation in scaling, but that doesn't work either.

Any help would be greatly appreciated. It feels like something obvious I'm missing, but I've googled myself to death and not got any joy.

Regards Neil

2
Have you ruled out the case where there's some "invisible" or very small graphic in the rectangle MovieClip that would result in it being higher than intended? What if you clear the keyframe and recreate the rectangle again, do you still get the same result?Strille
Thanks Strille. You're on to something there. When I stripped the code back to a single button with nothing else on the stage, it started working as expected. I'll start building it up again and see where it breaks. Many thanks for the advice!! :-DNEIL STRONG

2 Answers

1
votes

Try this : rect2.y = rect1.y + rect1.height ;

1
votes

Sounds like it might be a registration point issue.

The registration point is what specifies where an instance of the symbol will be positioned relative to it's x,y location.

If you double-click on your symbol in the library, you'll see the contents of your symbol and you'll see the little crosshair that represents your registration point. Typically you want to align your content either centered on that registration point or on the top left corner of your content.

My guess is that this might be your problem, but can't say for sure without seeing your content.

This registration point is also utilized for rotation. If you want to rotate an object around it's center point, you need to ensure that the registration point is in the center of the object.