Forum Topic: As: Dynamically Resizing Objects

(2,280 views • 23 replies)

This topic is 1 page long.

<< < > >>
None

SpamBurger

Reply To Post Reply & Quote

Posted at: 8/9/05 01:51 PM

SpamBurger NEUTRAL LEVEL 15

Sign-Up: 07/12/05

Posts: 4,747

AS: Main-Your Number One Resource For AS!
I dont know if this has been done before but if not, I thought it would be pretty helpful.
What?
In this tutorial you will be learning how to dynamically resize objects. You will learn the commands of _height and _width. You will also learn about _xscale and _yscale too.
Why?
Well, Im sure most of you wont really use this but this is a good way to simulate a z axis in flash. You can also use it for animaions as a shortcut to make an object get smaller or larger. So lets get started!
-----------
First I will explain the _height and _width commands. They are the easiest to work with. These are good to make a perfect circle or square. Ok, so say you want a perfect circle? Well, what you can do is draw your circle anyway you want and then convert it to a MC. After you have done that, you can give it the following code:
onClipEvent(load) {
_height=20;
_width=20;
}
The way that works is it tells flash that the circle's width should be 20 and its height should also be 20. That way, it makes the circle perfect! If you want, you can change the numbers to whatever you want. But if you want it perfect, you must keep the two numbers the same. Did I explain that well? I hope I did. I will now teach you some more about these commands.
-----------
Ok, so what if you want to change the width or height with the keyboard? This can be good for simulating a z axis. Well, first you could create a MC and give it this code:
onClipEvent(enterFrame){
if(Key.isDown(Key.RIGHT)) {
_width+=5;
}
}
Of course, you can change Key.RIGHT to whatever key you want. If you want to change the height and not the width, replace _width with _height. That will work good. Oh and one more thing, you can replace +=5 with -=5 if you want. The only difference is it will make the object's width get smaller and not bigger. Now I will explain how this works.
-----------
The way it works is it tells flash that if the right arrow key is pressed, it will increase the width by five pixels. Thats pretty easy, huh? Well, simulating a z axis isnt that hard either so I will now tell you how to do it.
-----------
Ok, simulating a z axis isnt to different then the previous script. But remember, this is only a simple way of doing it and its not reccomeneded for big 3D games. Okay, first create a MC that you want as the character. After you do that, you could give it this code:
onClipEvent(enterFrame){
if(Key.isDown(Key.UP)) {
_height-=5;
_width-=5;
}
if(Key.isDown(Key.DOWN)){
_height+=5;
_width+=5;
}
}
See, that's not that hard! You can see how it's like the other code. Basically, I added that when you press a key, the height and width get changed. Thats how you make something get smaller or bigger. Remember, its very basic and its only considered to be a "fake" z axis. I will now explain it.
-----------
The way it works is it tells flash that when you press the up arrow key, the height and width get smaller. It makes it look like the charcter is walking away. When you press the down arrow key, the width and height get bigger. It makes it look as if the character is walking forward. If you want to see a little sample, clickhere.
Now, since that is the basics, you will learn about something a little bit harder. It is _xscale and _yscale. I personally think they look better when simulating a z axis but thats me. I will only be explaining them vaguely becuase they are almost the same as height and width.
-----------
Ok, _xscale and _yscale. Pretty much the same idea but different. Okay, the thing you cant really do with these is make like a perfect circle. You can however use these to flip an object. But to do that, you have to adjust the little "+" symbol in the MC so that its in the middle of the MC. Once you do that, you can give the MC this code:
onClipEvent(enterFrame){
_xscale=-100;
}
What that does is it makes the object face the other way. It saves a lot of time becuase you dont have to use the free transform tool to make it perfect. It will be perfect if you use this code. Now, if you want to make it flip upside down, you can replace _xscale wth _yscale.
-----------
Now, what if you want to make that action happen only if you use the keyboard? Well, make a MC and give it this code:
onClipEvent(enterFrame){
if(Key.isDown(Key.LEFT)){
_xscale=-100;
}
}
The way the code works is it tells flash to make the object flip only if you press the left key. That code wont make the object move becuase this tutorial doesnt teach that.
-----------
Now, Im starting to get lazy so this last part will be quick. You can use _xscale and _yscale the same way you do with _width and _height. But the only difference is, I think using _xscale looks better. What you can do is to make an objects width get bigger is give it this code:
onClipEvent(enterFrame){
_xscale+=5;
}
Remember, you can use if(Key.isDown( commands to make it happen only when you press a certain key. You can also replace _xscale with _yscale or combine them.
-----------
Hopefully I included everything relative. I also think I did a good job explaining. If the codes dont work, its becuase of the auto-line breaker. For more help, check out
AS: Basic Movement

"However, the game received only two orders, one of which Molyneux speculated was from his mother." -Peter Molyneux's first game The Entrepreneur


None

<deleted>

Reply To Post Reply & Quote

Posted at: 8/9/05 01:53 PM

speed is way to slow but this is a good tut for the n00bs


None

T-H

Reply To Post Reply & Quote

Posted at: 8/9/05 02:03 PM

T-H LIGHT LEVEL 39

Sign-Up: 01/07/04

Posts: 4,893

A whole AS on manipulating a single object property?


None

SpamBurger

Reply To Post Reply & Quote

Posted at: 8/9/05 02:05 PM

SpamBurger NEUTRAL LEVEL 15

Sign-Up: 07/12/05

Posts: 4,747

At 8/9/05 02:03 PM, T-H wrote: A whole AS on manipulating a single object property?

Well, some people might need it. lol

"However, the game received only two orders, one of which Molyneux speculated was from his mother." -Peter Molyneux's first game The Entrepreneur


None

TrueDarkness

Reply To Post Reply & Quote

Posted at: 8/9/05 02:07 PM

TrueDarkness EVIL LEVEL 27

Sign-Up: 08/31/04

Posts: 4,718

this reminds me of something I made. Check this out: http://img188.images..=balltestgame2oq.swf

not only does it zoom in and out fo the ball but it rotates, moves it, rotates and zooms, and a whole bunch of stuff. For a hidden easter egg type "well fuck you" also lmao


None

<deleted>

Reply To Post Reply & Quote

Posted at: 8/9/05 02:11 PM

At 8/9/05 02:07 PM, True_Darkness wrote: bunch of stuff with a link

that kicks the shit out of this topic you should make a AS about that


None

T-H

Reply To Post Reply & Quote

Posted at: 8/9/05 02:17 PM

T-H LIGHT LEVEL 39

Sign-Up: 01/07/04

Posts: 4,893

At 8/9/05 02:11 PM, PirateNinjaOfDoom wrote:
At 8/9/05 02:07 PM, True_Darkness wrote: bunch of stuff with a link
that kicks the shit out of this topic you should make a AS about that

That was just more property manipulation - including the property the topic is focused on. Although i did like the flip in/out effect.

Yeah I guess this will be useful for people who sont want to dig through other crap to get this info.


None

TrueDarkness

Reply To Post Reply & Quote

Posted at: 8/9/05 02:20 PM

TrueDarkness EVIL LEVEL 27

Sign-Up: 08/31/04

Posts: 4,718

At 8/9/05 02:17 PM, T-H wrote:
At 8/9/05 02:11 PM, PirateNinjaOfDoom wrote:
At 8/9/05 02:07 PM, True_Darkness wrote: bunch of stuff with a link
that kicks the shit out of this topic you should make a AS about that
That was just more property manipulation - including the property the topic is focused on. Although i did like the flip in/out effect.

Yeah I guess this will be useful for people who sont want to dig through other crap to get this info.

T-H is correct, this thread isn't bad at all, a little simple yes but still, a lot of the stuff I used in my lil program is taken from a lot of the stuff he said, of couse I just didn't need him to tell me what to do when I made it lol.


None

Inglor

Reply To Post Reply & Quote

Posted at: 8/9/05 02:22 PM

Inglor NEUTRAL LEVEL 17

Sign-Up: 01/26/03

Posts: 10,948

very nicely put :) hurrah.


None

SpamBurger

Reply To Post Reply & Quote

Posted at: 8/9/05 03:48 PM

SpamBurger NEUTRAL LEVEL 15

Sign-Up: 07/12/05

Posts: 4,747

At 8/9/05 02:07 PM, True_Darkness wrote: this reminds me of something I made. Check this out: http://img188.images..=balltestgame2oq.swf



not only does it zoom in and out fo the ball but it rotates, moves it, rotates and zooms, and a whole bunch of stuff. For a hidden easter egg type "well fuck you" also lmao

Thats really nice! I should of included some of that here.

"However, the game received only two orders, one of which Molyneux speculated was from his mother." -Peter Molyneux's first game The Entrepreneur


None

Mogly

Reply To Post Reply & Quote

Posted at: 8/11/05 09:10 PM

Mogly LIGHT LEVEL 25

Sign-Up: 09/05/04

Posts: 10,336

good tut.

but how do you make it increase from centre?

~ MogTom ~ Dont fuck around with my dog. All that I can see I steal. ~
NG FFR ~ Automatic for the people.

BBS Signature

None

SpamBurger

Reply To Post Reply & Quote

Posted at: 8/11/05 09:15 PM

SpamBurger NEUTRAL LEVEL 15

Sign-Up: 07/12/05

Posts: 4,747

At 8/11/05 09:10 PM, Mogly wrote: good tut.

but how do you make it increase from centre?

You have to double click the MC and adjust the little + symbol so its in the middle of the MC.

"However, the game received only two orders, one of which Molyneux speculated was from his mother." -Peter Molyneux's first game The Entrepreneur


None

Mogly

Reply To Post Reply & Quote

Posted at: 8/11/05 09:16 PM

Mogly LIGHT LEVEL 25

Sign-Up: 09/05/04

Posts: 10,336

At 8/11/05 09:15 PM, SpamBurger wrote:
At 8/11/05 09:10 PM, Mogly wrote: good tut.

but how do you make it increase from centre?
You have to double click the MC and adjust the little + symbol so its in the middle of the MC.

oh woops, schoolboy error

~ MogTom ~ Dont fuck around with my dog. All that I can see I steal. ~
NG FFR ~ Automatic for the people.

BBS Signature

None

Mogly

Reply To Post Reply & Quote

Posted at: 8/11/05 09:23 PM

Mogly LIGHT LEVEL 25

Sign-Up: 09/05/04

Posts: 10,336

this could be used to make a good FPShooter, as some kinda sniper scope.

(as if, anyone gives a shit) but now, for the secound time in NG history, you can see were i live... click(hold right to zoom)

~ MogTom ~ Dont fuck around with my dog. All that I can see I steal. ~
NG FFR ~ Automatic for the people.

BBS Signature

None

SpamBurger

Reply To Post Reply & Quote

Posted at: 8/11/05 09:26 PM

SpamBurger NEUTRAL LEVEL 15

Sign-Up: 07/12/05

Posts: 4,747

At 8/11/05 09:23 PM, Mogly wrote: this could be used to make a good FPShooter, as some kinda sniper scope.

(as if, anyone gives a shit) but now, for the secound time in NG history, you can see were i live... click(hold right to zoom)

Pretty good! But this tut only covers a fake z axis. It might be simple but I also suggest you guys check out AS: 3D-intermediate.

"However, the game received only two orders, one of which Molyneux speculated was from his mother." -Peter Molyneux's first game The Entrepreneur


None

Kipling

Reply To Post Reply & Quote

Posted at: 8/24/05 05:48 PM

Kipling NEUTRAL LEVEL 13

Sign-Up: 05/04/04

Posts: 2,641

Best 12 year old ever/

I was twelve until 3 days ago.

None

Rustygames

Reply To Post Reply & Quote

Posted at: 8/24/05 05:50 PM

Rustygames LIGHT LEVEL 18

Sign-Up: 05/07/05

Posts: 6,662

??? The Z axis is always fake because flash doesnt have a Z axis
But I know what you mean

- Matt, Rustyarcade.com


None

SpamBurger

Reply To Post Reply & Quote

Posted at: 8/24/05 07:12 PM

SpamBurger NEUTRAL LEVEL 15

Sign-Up: 07/12/05

Posts: 4,747

At 8/24/05 05:48 PM, kipling wrote: Best 12 year old ever/

I was twelve until 3 days ago.

Who are you talking too? If me, I just turned 12 a week ago.

"However, the game received only two orders, one of which Molyneux speculated was from his mother." -Peter Molyneux's first game The Entrepreneur


None

master-of-disaster1

Reply To Post Reply & Quote

Posted at: 8/24/05 07:43 PM

master-of-disaster1 NEUTRAL LEVEL 02

Sign-Up: 08/15/05

Posts: 12

At 8/24/05 07:12 PM, SpamBurger wrote:
At 8/24/05 05:48 PM, kipling wrote: Best 12 year old ever/

I was twelve until 3 days ago.
Who are you talking too? If me, I just turned 12 a week ago.

I think he was talking to you...


None

Kipling

Reply To Post Reply & Quote

Posted at: 8/30/05 08:42 AM

Kipling NEUTRAL LEVEL 13

Sign-Up: 05/04/04

Posts: 2,641

At 8/24/05 07:12 PM, SpamBurger wrote:
At 8/24/05 05:48 PM, kipling wrote: Best 12 year old ever/

I was twelve until 3 days ago.
Who are you talking too? If me, I just turned 12 a week ago.

Yeah you.


None

xamm

Reply To Post Reply & Quote

Posted at: 11/19/05 08:05 PM

xamm EVIL LEVEL 08

Sign-Up: 10/25/04

Posts: 674

can you make it so when it reaches a a specific size it stops? that would be cool


None

nitro-goat

Reply To Post Reply & Quote

Posted at: 8/31/06 11:46 AM

nitro-goat LIGHT LEVEL 06

Sign-Up: 04/27/05

Posts: 117


None

Depredation

Reply To Post Reply & Quote

Posted at: 8/31/06 11:52 AM

Depredation LIGHT LEVEL 17

Sign-Up: 09/05/05

Posts: 4,781

At 8/31/06 11:46 AM, nitro_goat wrote: Nice tut
It'll come in handy!

Why did you bump a nine month old topic?

BBS Signature

None

TrueDarkness

Reply To Post Reply & Quote

Posted at: 8/31/06 11:54 AM

TrueDarkness EVIL LEVEL 27

Sign-Up: 08/31/04

Posts: 4,718

At 8/31/06 11:46 AM, nitro_goat wrote: Nice tut
It'll come in handy!

Lol, it's been here for over a year... it's been coming in handy along with all the other AS threads =p


All times are Eastern Standard Time (GMT -5) | Current Time: 11:15 PM

<< Back

This topic is 1 page long.

<< < > >>
You need a Grounds Gold Account to post on the NG BBS! If you don't have one, click here to sign up now! It's fast, free, and easy — and opens up tons of great NG features!