PDA

View Full Version : What is AVM2 relates to AS3



ayumilove
March 22nd, 2009, 06:15 AM
I know that AS3 [Actionscript 3] is used for programming a flash/swf.
But what does it do with AVM2 [Actionscript Virtual Machine]?
And What is actionscript virtual machine 1 different than 2? *puzzled*

ayumilove
March 23rd, 2009, 08:23 AM
bump*

McGuffin
March 23rd, 2009, 08:38 AM
AVM2 is basically what runs AS3 code in the Flash Player, and AVM1 is what runs AS1 and AS2 code. So when you load an AS2 SWF into an AS3 app, the AS2 SWF actually runs using AVM1.

Confused enough? It's not something you need to be worried about persay, the AVMs run internally and there's nothing you can do to customize their behavior (outside of some garbage collection behaviors in AVM2 using AS3).

wvxvw
March 23rd, 2009, 08:52 AM
Mmm... I'd say this doesn't entirely explain what virtual machine is, and what is VM in the FlashPlayer context.
So, first:
http://en.wikipedia.org/wiki/Virtual_machine
Dealing with flash player, virtual machine is a program that knows how to read ABC (ActionScript Bytecode) and how to execute it. But you don't program for VM directly, that's what the compiler is for - it translates your code into a set of simpler directives that VM can later pick up and execute. Basically, the AVM is the biggest part of the player as a program. And AVM runs in yet another virtual machine, which is your operating system environment, and that later VM talks to the hardware of your computer.

DfKimera
March 23rd, 2009, 09:36 AM
Mind you, AVM2 brought a significant speed increase to Flash Player. It came with a new JIT compiler, which is what compiles the ASC code down to machine language on the fly, being much faster and lighter then AVM1. On Flash Player 9+, both co-exist so movies created using earlier versions of Flash can be executed.

senocular
March 23rd, 2009, 10:11 AM
On Flash Player 9+, both co-exist so movies created using earlier versions of Flash can be executed.

That's an important point, but at the same time it is also important to understand that AVM2 IS a different virtual machine. Since it only executes AS3 code, leaving AS2 code to the original AVM1, AS2 projects cannot talk directly with AS3 projects. This is why you see hacks using LocalConnection for being able to have AS3 SWFs communicate with AS2 SWFs. And while an AS3 SWF can load an AS2 SWF, an AS2 SWF cannot load an AS3 SWF. Since AVM2 was created after AVM1, it knew AVM1 existed and could allow it to run a child SWF when loaded. AVM1 was designed not knowing AVM2 would ever exist so AVM1 (AS1/AS2) SWFs continue to be blocked from loading AS3 (AVM2) SWFs.

Krilnon
March 23rd, 2009, 11:12 AM
how to read ASC (ActionScript Bytecode)

compiles the ASC code

Okay, I know that this will sound unreasonably picky, but aren't ActionScript bytecode files referred to as ABC files? That's why you can get ABC errors and such. ASC is the name of the compiler (ActionScript compiler). It's hard to explain how confused I was when I ran across 'ASC' in two posts in a row and both times it was used where I was expecting 'ABC'.

wvxvw
March 23rd, 2009, 12:49 PM
Yeah, you're right, that was a typo, fixed. Heh...