1

I'me trying to understand some Action Script 3 features in order to port some code.

Code 1

How does the "++" influences the index part mean? If idx_val=0 then what xvaluer index will be modified?

xvaluer(++idx_val) = "zero";

Code 2

Then I have this: what is the meaning of this part of code? What is being assigned to bUnicode in the last 3 lines? (can you explain me the "<<"s and ">>"s)

bUnicode = new Array(2);
i = (i + 1);
i = (i + 1);
bUnicode[0] = aData[(i + 1)] << 2 | aData[(i + 1)] >> 4;
i = (i + 1);
bUnicode[1] = aData[i] << 4 | aData[(i + 1)] >> 2;

Code 3

I haven't the faintest idea of what is happening here. What is "as" ? What is the "?" ?

bL = c > BASELENGTH ? (INVALID) : (s_bReverseLPad[c]);

Code 4

What is "&&" ?

  if ((i + 1) < aData.length && s_bReverseUPad(aData((i + 1))) != INVALID)

Code 5

What is "as" ? What is the "?" ?

n2 = c < 0 ? (c + 256)  as  (c)
bOut.push(n1 >> 2 & 63)
bOut.push((n1 << 4 | n2 >> 4) & 63)//What is the single "&" ?
bOut.push(n2 << 2 & 63)

Finally, what are the differences between "||" and "|", and between "=" and "==" ?

beppe9000
  • 1,056
  • 1
  • 13
  • 28

1 Answers1

6

Code 1: ++i is almost the same thing as i++ or i += 1; The only real difference is that it's modified before it is evaluated. Read more here.

Code 2: << and >> are bitwise shifts, they literally shift bits by one place. You really need to understand Binary before you can mess about with these operators. I would recommend reading this tutorial all the way through.

Code 3: This one is called Ternary Operator and it's actually quite simple. It's a one line if / else statement. bL = c > BASELENGTH ? (INVALID) : (s_bReverseLPad[c]); is equivalent to:

if(c > BASELENGTH) {
    bL = INVALID;
} else {
    bL = s_bReverseLPad[c];
}

Read more about it here.

Code 4: "The conditional-AND operator (&&) performs a logical-AND of its bool operands, but only evaluates its second operand if necessary." There is also the conditional-OR operator to keep in mind (||). As an example of the AND operator here is some code:

if(car.fuel && car.wheels) car.move();

Read more about it here.

Code 5: From AS3 Reference: as "Evaluates whether an expression specified by the first operand is a member of the data type specified by the second operand." So basically you're casting one type to another, but only if it's possible otherwise you will get null.

& is Bitwise AND operator and | is Bitwise OR operator, again refer to this article.

= and == are two different operators. The former(=) is called Basic Assignment meaning it is used when you do any kind of assignment like: i = 3;. The later(==) is called Equal to and it is used to check if a value is equal to something else. if(i == 3) // DO STUFF;. Pretty straight forward.

The only part that doesn't make sense to me is the single question mark. Ternary Operator needs to have both ? and :. Does this code actually run for you? Perhaps a bit more context would help. What type is c?

n2 = c < 0 ? (c + 256) as (c)

Community
  • 1
  • 1
Iggy
  • 4,767
  • 5
  • 23
  • 34
  • Thank you for your answer. I'm done. I you wanted some more context, here it is: http://pastebin.com/piFaSULT – beppe9000 Dec 01 '14 at 18:59
  • Looks like you made a copy error. The line is actually `n2 = c < 0 ? (c + 256) : (c);` And that means it's a `ternary operator`! – Iggy Dec 01 '14 at 21:16