Reverse Movieclip scale in preloader

Hi,
I have a preloader that works by scaling a movie clip based on percent loaded. As it is at the moment  it scales the movieclip from 0% to 100%. I need it to scale from 100% to 0%.

If anyone can have a look at the actionscript 2.0 as attached and give me some help that would be awesome.

Thanks
bar_mc.bar._xscale = 0;
onEnterFrame = function () {
	//Get bytes loaded of _root timeline and calculate percentage loaded based on total bytes
	loading = _root.getBytesLoaded();
	total = _root.getBytesTotal();
	percentage = Math.round((loading / total) * 100);
	if (isNaN(percentage)) {
		percentage = 0;
	}
	//Move preloader bar and text field based on percentage loaded
	bar_mc.bar._xscale += (percentage - bar_mc.bar._xscale) / 5;
	percentage_mc._x = bar_mc.bar._width - percentage_mc._width / 2;
	//Display percentage value in text field
	percentage_mc.percentage.text = Math.round(bar_mc.bar._xscale);
	//Check when _root has loaded completly, then trigger preloader fade out and end onEnterFrame loop
	if (bar_mc.bar._xscale > 98 && percentage == 100) {
		//Display percentage value in text field
		percentage_mc.percentage.text = Math.round(bar_mc.bar._xscale);
		if (this._alpha > 0) {
			this._alpha += (-this._alpha) / 4;
		} else {
			_parent.play();
			delete this.onEnterFrame;
		}
	}
};
stop();

Open in new window

LVL 1
flashjordanAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

courtthreeCommented:
Hi mate,

I would take a slightly different approach and not use _xscale in this case. If you manipulated the _x and _width properties of your load bar, you'd get the effect you were looking for. Let me know if you need me to write any code out for you.
0
flashjordanAuthor Commented:
That would be a great help. what I have is a bottle that I wish the content... drink to reduce as the movie loads... What I have done is use a bar preloader, but the problem is that all preloaders increase in size rather than reduce in size. Actionscript is not my best point and I have no idea how to manipulate this.

I would really appreciate your help
0
courtthreeCommented:
Ah ha, so a slightly different approach again then. Really, all we need is a block of colour that moves down the page inside a bottle-shaped layer mask! So, are you able to create a layer mask for the bottle and a drink-coloured box inside it? Once you've done that, post back here and we'll code it up.
0
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

flashjordanAuthor Commented:
I have attached what I have been working on...
Thank you
bottlepreloader.zip
0
courtthreeCommented:
OK mate, will download and put something together. Might take me a couple of hours, standby!
0
flashjordanAuthor Commented:
As you will see... the drink fills up, when really it needs to empty.
Thanks for all your help, a few hours is no problem.
0
courtthreeCommented:
Cool mate, I'm on it.
0
courtthreeCommented:
Hi mate,

That file didn't zip properly and I can't extract it. Can you try again for me.
0
alien109Commented:
percentage = 100 - Math.round((loading / total) * 100);

This should give you what you are looking for, if I'm understanding the problem correctly.
0
alien109Commented:
FYI, this will give you the numbers that you are looking for, however - it won't work with how you currently have the code structured.
0
flashjordanAuthor Commented:
Apparently EE will not allow FLA upload... very strange... not even in a zip file.
You can download at conceptparadise.com/bottlepreloader.zip

I tried adding your code and no luck.

I hope the fla helps

Thanks
0
alien109Commented:
try changing the extension of the FLA to .txt, and then upload.
0
flashjordanAuthor Commented:
0
alien109Commented:
I couldn't open that. Renamed to bottlepreloader.fla, but Flash gives me an unexpected file format error when opening it.

What version of Flash is that?
0
courtthreeCommented:
Hi FlashJordan

I still can't can't download and access your files! Post your email address, I'll email you and you can reply with the files...
0
courtthreeCommented:
OK, I can't get your files so I'll just write the explanation and code right here!

Here's a step by step guide:

1. Draw the shape of your bottle either in Flash or Illustrator
2. Designate the bottle as a mask layer
3. Draw a box on the layer beneath
4. Make the box a symbol (of type MovieClip) and give it an instance name of "drink"
5. Resize the box (drink) so that it is at least as big as the bottle shaped mask
6. Mask the drink by dragging its layer icon into the layer icon of the bottle shape layer
7. Now you should have the shape of a bottle on the stage
8. Create a new layer called "Actions" (if you haven't already)
9. Add the below code snippet to the actions layer:

* Note that I have allowed a 60px margin at the top of the page (hence the 60 added to the y position of the drink.

Please come back to me if anything is not clear!
// Stop the movie here
stop();
 
// An onEnterFrame behaviour to measure load progress
onEnterFrame = function():Void {
	
	// Evaluate and revaluate the vars you'll need to move your symbols around
	var nBL:Number = this.getBytesLoaded();
	var nTB:Number = this.getBytesTotal();
	var nPL:Number = (nBL / nTB) * 100;
	
	// Move the drink down with the load progress
	drink._y = 60 + (drink._height / 100 * nPL);
	
	// Perform actions when we're fully loaded
	if (nPL == 100) {
		// Get rid of the onEnterFrame now it's done its job
		delete onEnterFrame;
		// Play the main timeline
		play();
	};
	
};

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
flashjordanAuthor Commented:
That was the perfect solution, easy to understand and worked perfectly
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Adobe Flash

From novice to tech pro — start learning today.