Log in

View Full Version : Wrong line height



neo_philiac
05-07-2008, 07:27 PM
Hello I am having a simple problem





var rectHeight = 37;

var rectWidth = 37;

tmp_big.lineStyle(rectWidth,color_tmp,100,true,"none","square", 1);
tmp_big.moveTo(0, (rectHeight));
tmp_big.lineTo(0, (-(rectHeight)));
tmp_big._x = (Stage.width-1280)+ 640; // Just trying to put the shape in a certain position
tmp_big._y = Stage.height/2; // Change registration point



The width is perfect when i draw the line but the height is 3 times 37. What am i doing wrong?

Medyman
05-07-2008, 10:29 PM
First, you might want to review the recommended syntax for movieclip.lineStyle (http://www.adobe.com/support/flash/action_scripts/actionscript_dictionary/actionscript_dictionary535.html)

Second, I think if you change
tmp_big.lineTo(0, (-(rectHeight))); to

tmp_big.lineTo(0, 0);
That might fix it.

neo_philiac
05-08-2008, 01:56 PM
Thanks Medyman. But if I put this:


tmp_big.lineStyle(rectWidth, color_tmp, 100);
tmp_big.moveTo(0, rectHeight);
tmp_big.lineTo(0,0);
tmp_big._x = (Stage.width-1280)+ 640;
tmp_big._y = Stage.height/2;

The line comes out round and the height has the same problem. So here is a workaround I did.


/* tmp_big.lineStyle(1,color_tmp,100,true,"none","square");
tmp_big.beginFill(color_tmp, 100);
tmp_big.moveTo(0, 0);
tmp_big.lineTo(0, rectHeight);
tmp_big.lineTo(rectWidth, rectHeight);
tmp_big.lineTo(rectWidth,0);
tmp_big.lineTo(0,0);
tmp_big.endFill();
tmp_big._x = ((Stage.width-1280)+ 640) - (rectHeight/2);
tmp_big._y = (Stage.height/2) - (rectWidth/2);

The problem with this is that the registration point os no longer middle. Is there a reason ?

Please help.

Medyman
05-08-2008, 03:48 PM
What is it that you're going for? A 37x37 square?

neo_philiac
05-08-2008, 06:18 PM
Well the thing is I will give it a certain number for height and width and the registration point should be in the middle. I t could be a square or rectangle.

Medyman
05-08-2008, 07:15 PM
Ahh, I see...

Well, the registration point of any movieclip that is created dynamically will always be in the upper left hand corner. You can't change the registration point with ActionScript.

You can, of course, change a movieclip's position to mimic the behavior of something that has a registratin point in the center. To do this you would need to create a container around the rectangle/square. Then you'll align the center of the rectangle/square to the upper left hand corner of the container movieclip.

The commented out actions will center the container on the stage.


var rectHeight:Number = 120;
var rectWidth:Number = 300;

var container:MovieClip = this.createEmptyMovieClip("container", this.getNextHighestDepth());
var r:MovieClip = container.createEmptyMovieClip("rectangle", container.getNextHighestDepth());
r.beginFill(0xee0000, 100);
r.moveTo(0, 0);
r.lineTo(rectWidth, 0);
r.lineTo(rectWidth, rectHeight);
r.lineTo(0, rectHeight);
r.endFill();

r._x = -r._width/2
r._y = -r._height/2

// Centers the container on the stage.
// container._x = Stage.width/2;
// container._y = Stage.height/2;