-
Scaling Movieclips Function Wanted
Hi guys,
I've got a project here - it's more tricky then it first appears (or it was to me!)
Price:
I don't want to insult anyone by naming a price - so look at the job, and give me a quote - I'll pay you paypal when it's done - I've been on this board for years - so hopefully you can trust me to pay up.
The job:
I've got a movieclip - called "container" - in "container", there is a movieclip called "inner". (container.inner)
I want to resize "container" to any shape or size I want -- and then -- I want the "inner" movieclip to always stay in proportion of its original scale.
So, I will drag and resize the "container" movieclip -- then run the code to see the result.
I want 1 function - that will work with any shape "container" or any shape "inner" (for example - square or rectangle).
"inner" should never get bigger then "container"
I've done a few examples:
example-of-scale.png
In the first set of pictures - "inner" is a square. No matter what shape the "container" becomes - "inner" is always a square - just bigger/smaller to suite its container.
In the second set - "inner" is a rectangle with a larger X - once again, no matter how big "container" is - "inner always stays correct.
Thanks:
I hope this has explained the project - I don't want any hard-coded sizes - "inner/container" can be any size or shape. But "inner" always has to be as big, or small as it can be to suite its "container"
Thanks for looking! I Hope someone can do this project.
Kind regards,
-
AS2 or AS3 ?
Do clips have center registration or upper left?
-
Originally Posted by dawsonk
AS2 or AS3 ?
Do clips have center registration or upper left?
Hi - as3 is great. If you don't know as3 but can work out the above in as2 - I can convert it.
Registration can be top, middle, bottom. I don't mind. You make it work - and I'll work with the reg points you tell me too
-
-
Fantastic Dawsonk - you're a genius!
I've PM'd you a little big more to add onto this project.
Many thanks.
-
Just to follow up - since Dawsonk did me the original code - I've got some more to do based on the original project. If anyone can do this - please just let me know the price.
(Also Dawsonk - please let me know how much I owe you! Thanks again!)
I have attached two fla files -
working.fla -- this is how the code should work - Resize the stage - and the inner movieclip resizes to be as big as it can!
There is a little problem in this code though -
var originalWidth:Number = Math.round((obj.width/obj.scaleX));
var originalHeight:Number = Math.round((obj.height/obj.scaleY));
I wrote these lines - and they are probably not the correct way to work out the original size of the inner movieclip - if anyone knows how to fix this?)
The new problem is:
not-working.fla -- this is the same as the other fla --- BUT now container.inner - is inside ANOTHER movieclip - meaning there are 2 parents. The function does not work with 2 parents. As the scale of "container" is not taken into account.
If anyone can fix this -- just let me know how much I owe you!
Attachements: Working: working.fla Not Working: not-working.fla
Thanks again.
-
.
Hi,
I took a look too, with the not working one and keeping your code mostly
PHP Code:
stage.scaleMode = StageScaleMode.NO_SCALE;
stage.align = StageAlign.TOP_LEFT;
stage.addEventListener(Event.RESIZE, resizeScreen);
stage.dispatchEvent(new Event(Event.RESIZE));
function resizeScreen(e:Event):void
{
//outer_container.width = stage.stageWidth;
//outer_container.height = stage.stageHeight;
outer_container.container.width = stage.stageWidth;
outer_container.container.height = stage.stageHeight;
doSize(outer_container.container.inside);
}
function doSize(obj:MovieClip):void
{
var referer = obj.parent;
var originalWidth:Number = Math.round((obj.width / obj.scaleX));
var originalHeight:Number = Math.round((obj.height / obj.scaleY));
var amt:Number = Math.min(referer.width / originalWidth, referer.height / originalHeight);
obj.scaleX = (amt * (1 / referer.scaleX));
obj.scaleY = (amt * (1 / referer.scaleY));
obj.x = ((referer.width / 2) * (1 / referer.scaleX)) - (obj.width / 2);
obj.y = ((referer.height / 2) * (1 / referer.scaleY)) - (obj.height / 2);
}
-
Thanks fruitbeard - but the outer_container has to be the one that resizes to the stage size
-
.
Hi,
I.m not entirely sure which bit you want to scale,
PHP Code:
stage.scaleMode = StageScaleMode.NO_SCALE;
stage.align = StageAlign.TOP_LEFT;
stage.addEventListener(Event.RESIZE, resizeScreen);
stage.dispatchEvent(new Event(Event.RESIZE));
function resizeScreen(e:Event):void
{
outer_container.width = stage.stageWidth;
outer_container.height = stage.stageHeight;
// outer_container.container.width = stage.stageWidth;
//outer_container.container.height = stage.stageHeight;
doSize(outer_container.container.inside);
}
function doSize(obj:MovieClip):void
{
var referer = obj;
var originalWidth:Number = Math.round((obj.width / obj.scaleX));
var originalHeight:Number = Math.round((obj.height / obj.scaleY));
var amt:Number = Math.min(referer.width / originalWidth, referer.height / originalHeight);
obj.scaleX = (amt * (1 / referer.scaleX));
obj.scaleY = (amt * (1 / referer.scaleY));
obj.x = ((referer.width / 2) * (1 / referer.scaleX)) - (obj.width / 2);
obj.y = ((referer.height / 2) * (1 / referer.scaleY)) - (obj.height / 2);
}
-
If you download the "working.fla"
I'd like the "not-working.fla" to produce the same result - the same scaling and positioning as the "working.fla"
The only code that can be changed is in the "doSize" function.
There may also be a problem with the two variables originalWidth and originalHeight --- as I wrote them lines and am not as good coder as Dawsonk
-
.
Hi,
What is the original code that dawsonk wrote
-
In the original code, the sizes were set like - originalWidth = 300, originalHeight = 150
But as I need the function to be able to work with any movieclips, I can't have them hardcoded like that. The function needs to work out the "inner" original size without any hardcoded numbers.
Thanks again for the help
-
.
Hi,
I can't seem to get my head around it, perhaps this, although this also scales the container
PHP Code:
stage.scaleMode = StageScaleMode.NO_SCALE;
stage.align = StageAlign.TOP_LEFT;
stage.addEventListener(Event.RESIZE, resizeScreen);
stage.dispatchEvent(new Event(Event.RESIZE));
function resizeScreen(e:Event):void
{
outer_container.width = stage.stageWidth;
outer_container.height = stage.stageHeight;
outer_container.container.width = stage.stageWidth;
outer_container.container.height = stage.stageHeight;
doSize(outer_container.container.inside);
}
function doSize(obj:MovieClip):void
{
var referer = obj.parent;
var originalWidth:Number = Math.round(obj.width / obj.scaleX);
var originalHeight:Number = Math.round(obj.height / obj.scaleY);
var amt:Number = Math.min(referer.width / originalWidth, referer.height / originalHeight);
obj.scaleX = (amt * (1 / referer.scaleX));
obj.scaleY = (amt * (1 / referer.scaleY));
obj.x = ((referer.width / 2) * (1 / referer.scaleX)) - (obj.width / 2);
obj.y = ((referer.height / 2) * (1 / referer.scaleY)) - (obj.height / 2);
}
-
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|