Flash actionscript

They have: 2 posts

Joined: Mar 2002

I wonder if anyone could explain to me how the " post increment operator"works e.g "expression++" Im baffled!

They have: 218 posts

Joined: Apr 2001

var x = 1;
x++; //add 1: x is now 2.

So in this case, the post increment operator is used to add one to a variable. That's a basic starting point.

TonyMontana
Electric Mountain

They have: 2 posts

Joined: Mar 2002

How is this different from the pre increment operator "++expression"

Suzanne's picture

She has: 5,507 posts

Joined: Feb 2000

In I think all languages, including actionscript...

++ by itself has the same result whether it's ++$a or $a++

BUT!

$a = 3
$b = $a++

Now $b = 3 and $a = 4

$a = 3
$b = ++$a

Now $b = 4 and $a = 4

They have: 218 posts

Joined: Apr 2001

code: var x = 1;
var y = x++ //Postfix increment: y is set to 1, then x is incremented to 2.

var x = 1;
var y = ++x //Prefix increment: x is incremented first, so y is set to 2.

Um...I wonder why this thread was moved into a...graphics forum? Wink

TonyMontana
akaMethodAir
ElectricMountain

They have: 105 posts

Joined: Jan 2002

Isn't it correct that it does not matter whether you use ++a or a++ if the only thing a line of code is doing is incrementing a value:

a = 3;
b = a++;

results in b = 4.

but, the difference comes when you're doing more complicated things, such as printing these values to the screen, for example, the ++a is incremented before the value is sent to the screen, the a++ is incremented after the value is sent to the screen. So the following has different effects:

print "The answer is" ++a;
print "The next answer is" a++;

Results in:

The answer is 4;
The answer is 3;

This is because most programming languages use a left--> right reading scheme of data, so the first says add 1 to whatever follows, the second says print a, then add 1.

CPRhosting.com - CPR Hosting...Giving life to the web
Custom-made Hosting Plans starting at $2

They have: 601 posts

Joined: Nov 2001

Yes, you're right.

++$_ The pre-increpment operator will increase the value of $_ first then assign it.

$_++ The post-increment operator will increase the value of $_ after it is assigned.

Perl has it's operators derived from C, so I'll use a C example here to examine what happens when we use the operator along with an assignment operation. This might help you to see more clearly how this is used.

main()
{
int count = 0, loop;

loop = ++count;  /* same as count = count + 1; loop = count;  */
printf("loop = %d, count = %d\n", loop, count);

loop = count++;  /* same as loop = count;  count = count + 1;  */
printf("loop = %d, count = %d\n", loop, count);
}


<strong>Sample Program Output:</strong>

loop = 1, count = 1
loop = 1; count = 2
'

Hope this helps.

- wil

Suzanne's picture

She has: 5,507 posts

Joined: Feb 2000

Interesting, four replies saying the exact same thing four different ways. ha!

Tony, I think it was moved because it was a question intended for Flash, and Flash is a bit of a hybrid, but most Flash questions go in the Graphics area.

They have: 601 posts

Joined: Nov 2001

LOL! That's why Perl's motto is TMTOWTDI (There's More Than One Way To Do It) Smiling

They have: 218 posts

Joined: Apr 2001

In a lot of forums I see, the Flash graphics and code are separated. One of the Flash sites I'm building right now utilizes interactive volume crossfades, using the sound object and 3d interactive interfaces using Flash trignometry Math methods and arrays.

The work bears little resemblence to a graphics program like Photoshop. In fact, most of the work can be done in a text editor like Notepad.

Cheers,

TonyMontana
ElectricMountain

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.