1

UPDATE: Found some nice info on AVM2. I haven't been able to spend much time with it, but it definitely covers $init and $cinit (as well as $iinit, and a lot of other things). I'll post a response to this question if I get a good handle on the answer before someone else puts something up.


Got pulled into a long thread of link-hopping and googling about this today, but still don't have much of a grasp on what $cinit and $init are.

I care because I learned today that $cinit and $init are interpreted (by the FP, if I understand correctly), while everything else is compiled.

I think that $init refers to the given class's constructor function, and $cinit refers to the constructor of the object that creates the class. ... something like that...

Can anyone set me straight on this, or at least point me in a helpful direction?

Thanks.

Ross Henderson
  • 1,779
  • 16
  • 23
  • I'd also like a definitive answer to this. I think $cinit is the class constructor, and $init the static constructor. But again, not sure. – Danyal Aytekin Sep 09 '10 at 15:03
  • I might also add that $cinit and $init and $iinit are not interpreted and are definitely compiled! – jduncanator Jul 11 '14 at 13:31

2 Answers2

1

This is an old question, but as I know the answer I'll post here.

$cinit is the method that is called before any use of the class is required. It initializes all static members and runs any code that is in the static initializer. Think of it as the classes own constructor. For instance, if you had the following class in AS3:

public class SomeClass extends Object {
   static private const SOME_STATIC_VAR = 4;
   ....
}

Then the $cinit method would run before the class was ever used or even made reference to, and it would initialize the memory for SOME_STATIC_VAR and set its value to 4.

$init is the classes instance initializer. It's basically the classes constructor. For example:

public function SomeClass() {
  super();
  return;
}

Hope thats enough detail for you!

jduncanator
  • 2,154
  • 1
  • 22
  • 39
0

$cinit is to construct all static variables while the class are used for the first time.

Nilesh
  • 20,521
  • 16
  • 92
  • 148
Junjie
  • 1
  • 1