2. AVM2
Virtual Machine
ABC file
(compiled programs –
Constant data,
instructions from AVM2 instruction set
And metadata)
VM is a mechanism that takes as its input description of a computation
3. AVM2 - $cinit – Class Initializer
• $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
• 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.
AVM2 - $init – class instance Initializer
• $init is the classes instance initializer. It's basically the classes constructor. For example
5. Static Keyword
• With the help of $cinit method ,
• static variables and functions are initialized
globally and
• they are accessible for entire project by calling
their Class (not instance) .
6. addimediateCallback
Creates new callBackEntry Object and set its callback property to programmer
defined function, which is required to execute when there is a state change in the
object (ILinkableObject)
addGroupedCallback
• Creates new callBackEntry object (triggerEntry) and to its callback property a new
inline function, which wraps the programmer defined function is set.
• callBackEntry object (triggerEntry) is then added to global memory (static) with
key as programmer defined function
• And then through addImmediateCallback callBackEntry object (triggerEntry) is
added to local memory, instead of original function
7. addimediateCallback
Creates new callBackEntry Object and set its callback property
to programmer defined function, which is required to execute
when there is a state change in the object (ILinkableObject
“Store locally”
8. addGroupedCallback
• It creates new callBackEntry object (triggerEntry) and to its callback
sets a new inline function, which wraps the programmer defined
function.
• callBackEntry object (triggerEntry) is then added to global memory
(static) with programmer defined function being key to access
callBackEntry object (triggerEntry) .
• And then through addImmediateCallback callBackEntry object
(triggerEntry) is added to local memory), instead of original
function
“Wrap it and store the trigger Locally to a
programmer defined function globally ”
9. inlineFunction
A function can be executed in
two ways by adding flag
• inline function – (triggerEntry.callback) gets called first time, from local memory due to stateChange,
1. It execute second set of instructions,
2. adds the triggerEntry to global Queue (Static)
3. Note: original function is not executed
• Wrapper function gets called second time, from global memory due to ENTER_FRAME event.
1. It execute first set of instructions this time,
2. Original function gets executed
“Add to global queue when called from local Memory
Executes original function when called from Global queue”
10. 1. Event.ENTER_FRAME dispatched
2. Event.FRAME_CONSTRUCTED dispatched
3. Event.EXIT_FRAME dispatched
4. Event.RENDER dispatched
Loop 1 Loop 2
ENTER_FRAME
ENTER_FRAME
Callback added through
addImmediateCallback
executed
Wrapper function
added through
addGroupedCallback
executed, which in
turn executes
Original Function
Wrapper function
added through
addGroupedCallback
Executed to add them
to global Queue
11. registerLinkableChild / newLinkableChild
• Along with the callback function mentioned by the
Programmer, registered parent’s trigger Callback function
is also added through addImmediateCallback.
• So though you add one function, two functions are added
automatically.
• So any change in LinkableString value will execute two
sets of functions
• One Programmer Defined Functions
• Second linkableString’s registered parent
triggercallback method
12. How state change Works?
“Change in linkbaleObject caused by user ,
should also automate change in
the IlinkbaleObject’s registered parent.”
• When user changes the value of IlinkableObject,
• Programmer defined callback functions executes first
• Then registered parent trigger callback is called
• Which in turn calls parents callback Functions
• If parent has callback function added through grouped callback, they are
called in next cycle
14. Callback execution Frames
• Functions added through immediateCallback, are executed in same frame where
state change occurred.
• Functions added through grouppedCallback are executed in nextFrame in user
Code Section of Player Events , as groupedcallbacks are execute in ENTER_FRAME
Listener.
• If groupedCallback function , makes a state change to IlinkableObject , and if that
object has callback added though groupedcallback, they too will execute in same
frame not next frame, in user Code Section of Player Events
16. Class1 implements ILinkableObject
• property1: LinkableBoolean = newLinkableChild (this, LinkableBoolean)
• property2: LinkableNumber = newLinkableChild (this, LinkableNumber)
• property3: LinkableString = newLinkableChild (this, LinkableString )
Object1 = newLinkableChild (this, Class1)
• Object1.addImmediateCallBack( this, function-1);
• Object1.addGroupedCallback( this, function-2)
• Object1.property1.value = true; ----- function-1 Executed
• Object1.property2.value = 100; ----- function-1 Executed
• Object1.property3.value = “hi”; ----- function-1 Executed
----- function-2 Executed
Frame 1
Frame 2
“Object-1 stage changed three times, function1 added
through immediate callback was called three times,
function 2 added through grouped callback was called
only once”
17. Quiz
• If we create a scatterplot tool in updatePanel method , which is called due to
enterframe Listener, and then we access the child say checkbox in
updatePanelPos, which is also added through groupedcallback, will the
checkbox is available to access ?
• Answer - No. As both code execute in same frame , and scatterplot tool in not
ready for access yet . scatterplot tool haven’t completed its lifeCycle yet.
SactterplotTool components are ready for access only in next frame
18. Frame 2 Frame 2
triggerEntry.callback() = function():void{
If (_runningGroupedCallbacksNow){
//execute – user Func
}
else{
// call in next frame
}
};
runningGroupedCallbacksNow = true
Frame 1
runningGroupedCallbacksNow = false