Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Drawig a box enlarges an MC size? :/

Status
Not open for further replies.

Leozack

MIS
Oct 25, 2002
867
GB
Here's a strange problem. I put the following code into flash 6 mx AS2
Code:
stageWidth = 400;
stageHeight = 300;

containerMC = this.createEmptyMovieClip("containerMC_mc", 1);

TestBorderSize = 2;

containerMC.lineStyle(10, 0x123123, 70);
containerMC.moveTo(TestBorderSize/2, TestBorderSize/2);
containerMC.lineTo((TestBorderSize/2)+stageWidth , TestBorderSize/2);
containerMC.lineTo((TestBorderSize/2)+stageWidth , (TestBorderSize/2)+stageHeight );
containerMC.lineTo(TestBorderSize/2, (TestBorderSize/2)+stageHeight );
containerMC.lineTo(TestBorderSize/2, TestBorderSize/2);

trace("ContainerW = " + containerMC._width + ", ContainerH = " + containerMC._height);

And it produces this "ContainerW = 420, ContainerH = 320".

I've no idea why this is happening but I can't continue my app now until someone shows me what the problem is :(

The result is a gap down the bottom and right side that is ruining all the layout, eg look here

_________________________________
Leozack
Code:
MakeUniverse($infinity,1,42);
 
Here's a slight rework of the code to make it more obvious.

Code:
Stage.align = "TL";

containerMC = _root.createEmptyMovieClip("containerMC_mc",1);
bgMC = containerMC.createEmptyMovieClip("bgMC_mc",2);
borderMC = containerMC.createEmptyMovieClip("borderMC_mc",3);

BoxWidth = 400;
BoxHeight = 300;
BorderSize = 20;

trace ("Empty : ContainerMC width = " + containerMC._width + "   containerMC height = " + containerMC._height);

fillType = "linear";
colours = [0x00FF00, 0x0000FF];
alphas = [70, 70];
ratios = [0, 255];
matrix = {matrixType:"box", x:0, y:0, w:BoxWidth, h:BoxHeight, r:270/180*Math.PI};

bgMC.lineStyle(0, 0xFF0000, 0);
bgMC.beginGradientFill(fillType, colours, alphas, ratios, matrix);
bgMC.moveTo(0, 0);
bgMC.lineTo(0+BoxWidth, 0);
bgMC.lineTo(0+BoxWidth, 0+BoxHeight);
bgMC.lineTo(0, 0+BoxHeight);
bgMC.lineTo(0, 0);
bgMC.endFill();

trace ("No Border : ContainerMC width = " + containerMC._width + "   containerMC height = " + containerMC._height);

borderMC.lineStyle(BorderSize, 0xFF0000, 70);
borderMC.moveTo(BorderSize/2, BorderSize/2);
borderMC.lineTo((BorderSize/2)+BoxWidth-(BorderSize), BorderSize/2);
borderMC.lineTo((BorderSize/2)+BoxWidth-(BorderSize), (BorderSize/2)+BoxHeight-(BorderSize));
borderMC.lineTo(BorderSize/2, (BorderSize/2)+BoxHeight-(BorderSize));
borderMC.lineTo(BorderSize/2, BorderSize/2);

trace ("With Border : ContainerMC width = " + containerMC._width + "   containerMC height = " + containerMC._height);

The output it traces is te same result
Code:
Empty : ContainerMC width = 0   containerMC height = 0
No Border : ContainerMC width = 400   containerMC height = 300
With Border : ContainerMC width = 420   containerMC height = 320

_________________________________
Leozack
Code:
MakeUniverse($infinity,1,42);
 
If I do the same in AS3:
Code:
var boxW:uint = 400;
var boxH:uint = 300;
var bdr:uint = 20;
			
var sp:Sprite = new Sprite();
with(sp.graphics){
   lineStyle(bdr, 0);
				
   moveTo(bdr/2, bdr/2);
   lineTo(boxW - bdr/2, bdr/2);
   lineTo(boxW - bdr/2, boxH - bdr/2);
   lineTo(bdr/2, boxH - bdr/2);
   lineTo(bdr/2, bdr/2);
}
addChild(sp);
			
trace(sp.width, sp.height);
Output:
400 300

..I get the correct size.

Your first code has errors - you need to deduct border/2 instead of adding.

Your second code - can you try without the fill?

Kenneth Kawamoto
 
I just tried it with the filling commented out and got the same results :/ Have a play with the fla if you want (attached)

_________________________________
Leozack
Code:
MakeUniverse($infinity,1,42);
 
 http://www.romerch.com/ClipSize.zip
You're saying in no form do you get the results I get with the border (with or without fill) of 320 and 420? You can't reproduce it at all?
That's kinda messed up :/ I didn't think there was actual problems with as2/flash6 etc. I just tried running it in the stnadalone flash 9 player I have (I can't change the v6 used in ctrl+enter previews :( oh well) and it came up the same so it's not player 9 doing anything different to 6?

_________________________________
Leozack
Code:
MakeUniverse($infinity,1,42);
 
It seems if I draw a line accross the top
borderMC.moveTo(BorderSize/2, BorderSize/2);
borderMC.lineTo((BorderSize/2)+BoxWidth-(BorderSize), BorderSize/2);
then the container width goes up by half the border size and the height goes up by a full border size (410 & 320 in my case)
but if I draw a line along the side
borderMC.moveTo(BorderSize/2, (BorderSize/2)+BoxHeight-(BorderSize));
borderMC.lineTo(BorderSize/2, BorderSize/2);
then the container width goes up by a full border size and the height goes up by half border size.
If I draw both lines then both width & height go up by a full border size (20 in this case, to become 420/320 my usual answer)

So ... I can't draw a line without it's container being enlarged in parallel to it by borderwidth/half borderwidth

_________________________________
Leozack
Code:
MakeUniverse($infinity,1,42);
 
If I export your code into Flash 6 I get the wrong result like you do, but not if I export it to Flash 9 (that's basically Flash 8 in terms of AS1/2 movie) I get the correct size as I said.

Therefore this is not a player bug, but looks like a bug in the Flash 6 SWF file format itself.

You can add extra Maths ( - border) to get the right result, or update your Flash so that you can export it to Flash 8 format.

Kenneth Kawamoto
 
I don't really have the updating option (and I do prefer as2 to as3 currently, not as keen on the c# object obsessed style!) but I haven't come up with any maths that can correct the problem - possibly because I'm not a guru at how the flash stage really truely handles itself and its layers. It was hard enough work to draw borders floating above their fill on seperate layers so scrolling text layers could disappear under the border and stuff like that whilst keeping it all adjsuting correctly when resizing. Sadly 1 day I thought "why not make ti possible to put a border round the outside since now I know how ot make the flash transparent on the html page" and since then got stuck thanks to this bug :(

_________________________________
Leozack
Code:
MakeUniverse($infinity,1,42);
 
My goal is an app that reads its size from an xml file and then stretches maintaing ratio to fit whatever it's resized to. It works fine. But then I stick a border round the outside and the stage area expands an extra bit for no reason (the bug you suggest is in the flash 6 export or whichever). So ...ifI can't control the stage expansion - how can I make the app fill it if the stage keeps this random extra distance away from the border? I'm not sure what I can do :/

_________________________________
Leozack
Code:
MakeUniverse($infinity,1,42);
 
Everything is redrawn currently. Well that's a lie - it reads in the original size specs (eg 640*480) and builds the framework up to fit in that.
Then it constantly checks the stagesize and resizes the main container mc to fit it whilst maintaining aspect ratio.
I now have a floating layer outside the main container that tries to keep in place with it which contains a scrolling text layer masked to only show up in the right place (needs palyer 6.x.x or later to mask the text, which doesn't include my flas6mx preview player sadly, have to test the swf in standalone 9 player instead).
I'm thinking - I'll have to draw the outside border once again on a floating layer outside my main container mc tree. If I draw the border anywhere on the container mc tree then the whole container (including the extra space around the border) will be resized to fit in the stagesize.
But now I think about it (ouch my head) simply drawing a line border as big as the stage is causing the stage to expand, and no matter what layer I draw it on, this will happen, leaving a gap around the edge?

_________________________________
Leozack
Code:
MakeUniverse($infinity,1,42);
 
Maybe cos it's late and I've had little sleep but maybe because it's got so compliccaed, I'm not sure what you mean. Give me the Ken for Dummies version ;) As for using fill - how can I do that if the inside area isn't solid? you could draw the border with a fill then draw the fill on top with the actual fill, but due to alpha levels etc the fill may be transparent or whatever during usage and I don't see how else I could apply what you said about using fill instead of the line to draw the border.
Thanks a lot for your input btw, I've hardly touched the project since this stopped me :(

_________________________________
Leozack
Code:
MakeUniverse($infinity,1,42);
 
Code:
import mx.utils.Delegate; 

var mc:MovieClip;

setStage();
setMC();

function setStage():Void {
   with(Stage){
      scaleMode = "noScale";
      align = "TL";
   }
		
   var lo:Object = new Object();
   lo.onResize = Delegate.create(this, resize);
   Stage.addListener(lo);
}
	
function resize():Void {
   drawBdr();
}
	
function setMC():Void {
   mc = this.createEmptyMovieClip("mc", 1);
   drawBdr();
}
	
function drawBdr():Void {
   with(mc){
      clear();
      lineStyle(10, 0);
      moveTo(5, 5);
      lineTo(Stage.width - 5, 5);
      lineTo(Stage.width - 5, Stage.height - 5);
      lineTo(5, Stage.height - 5);
      lineTo(5, 5);
   }
}

Kenneth Kawamoto
 
Is that as3 for flash 8? Cos I'm using as2 for flash 6 remember :)

_________________________________
Leozack
Code:
MakeUniverse($infinity,1,42);
 
Pretty sure all that importing stuff started with flash 7 2004, and I copy/pasted it into my flash 6 mx and instantly got errors
Scene=Scene 1, Layer=Layer 1, Frame=1: Line 1: ';' expected
import mx.utils.Delegate;
Scene=Scene 1, Layer=Layer 1, Frame=1: Line 8: '{' expected
function setStage():Void {
Scene=Scene 1, Layer=Layer 1, Frame=1: Line 17: Unexpected '}' encountered
}

_________________________________
Leozack
Code:
MakeUniverse($infinity,1,42);
 
It is Flash 6 AS2.

You get errors because you're running AS1.

Let me rewrite it in AS1:
Code:
var mc;

setStage();
setMC();

function setStage() {
	with (Stage) {
		scaleMode = "noScale";
		align = "TL";
	}
	var lo = new Object();
	lo["parent"] = this;
	lo.onResize = function(){
		this.parent.resize();
	}
	Stage.addListener(lo);
}

function resize() {
	drawBdr();
}

function setMC() {
	mc = this.createEmptyMovieClip("mc", 1);
	drawBdr();
}

function drawBdr() {
	with (mc) {
		clear();
		lineStyle(10,0);
		moveTo(5,5);
		lineTo(Stage.width-5,5);
		lineTo(Stage.width-5,Stage.height-5);
		lineTo(5,Stage.height-5);
		lineTo(5,5);
	}
}

Kenneth Kawamoto
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top