Ultrashock Forums > Flash > ActionScript
Problem with container MC scaling
Member Blogs
 
Post Reply | View first unread | Rate Thread Search this Thread | Thread Tools | Display Modes

#1
Bookmark and Share!
Problem with container MC scaling
Old 4 Weeks Ago

hi,

i am working on an image gallery, in which the thumbnails will float up and down randomly, with the stageHeight as border.
This works all fine, but now I wanted to add it to a container, so I can change it to a new size (making it bounce not on the entire stageHeight).

Pls see code below, just a simple example without the floating function and only two testboxes, but enough to show the problem:

var container:MovieClip = new MovieClip();
addChild(container);

//including the following lines doesn't display anything anymore - leaving it out //works fine:
//container.height = 400;
//container.width = 400;

var firstBox:TestBox = new TestBox();
var secBox:TestBox = new TestBox();

container.addChild(firstBox);
container.addChild(secBox);

firstBox.x = 50;
secBox.x = 350;


Leaving the 2 lines in question out sizes the container to the whole stage again ...

pixum
postbit arrow 2 comments | 175 views postbit arrow Reply: with Quote   
pixum
Registered User
pixum is offline
seperator
Posts: 23
2008-07-18
pixum lives in Netherlands
pixum's Avatar
seperator

Ultrashock Member Comments:
Nutrox's Avatar Nutrox Nutrox is online now Nutrox lives in United Kingdom 1 Blog Entries 13 Creative Assets 4 Weeks Ago #2 Old  
Last edited by Nutrox : 4 Weeks Ago at 22:08.
Hi pixum,

I spotted your "pixum says hi" thread and thought I would say hello and welcome to Ultrashock while I'm in this thread.

Getting into the specifics about how display objects are resized in Flash is well beyond the scope of this thread, but I will try to nutshell it here. When you set the width or height of a display object it doesn't actually give the display object a fixed width or height, what happens is the scaleX and scaleY properties are changed so that the content is scaled to visually match the specified width and height (relative to the scaleX and scaleY values of the parent display object).

Because you are setting the width and height of your container while it is empty the scaleX and scaleY properties are being reduced to 0 (zero).

Code:
var container:MovieClip = new MovieClip();

container.width = 400;
container.height = 400;

trace( container.width );  // 0
trace( container.height ); // 0
trace( container.scaleX ); // 0
trace( container.scaleY ); // 0
One way to force a fixed width and height is to take advantage of the MovieClip's graphics object.

Code:
var container:MovieClip = new MovieClip();

setContainerSize( container, 400, 400 );

trace( container.width );  // 400
trace( container.height ); // 400
trace( container.scaleX ); // 1
trace( container.scaleY ); // 1

function setContainerSize( target:MovieClip, w:int, h:int ):void
{
	target.graphics.clear();
	// top-left
	target.graphics.beginFill( 0 );
	target.graphics.drawRect( 0, 0, 0, 0 );
	target.graphics.endFill();
	// bottom-right
	target.graphics.beginFill( 0 );
	target.graphics.drawRect( w, h, 0, 0 );
	target.graphics.endFill();
}
Alternatively you could write a custom display object class that handles it's own resizing and scaling etc.

Reply With Quote  
pixum's Avatar pixum pixum is offline pixum lives in Netherlands 4 Weeks Ago #3 Old  
hey nutrox, thanks, now that i read it it's quite obvious ... you can't scale nothing! thanks for the welcome, i'm happy to be here! looking forward to be part of the flash community ...
Reply With Quote  
Thread Tools
Display Modes Rate This Thread
Rate This Thread: