Movie::Invoke

Movie::Invoke
bool Invoke(const char* ppathToMethod, Value * presult, const Value* pargs, unsigned numArgs);
bool Invoke(const char* ppathToMethod, Value * presult, const char* pargFmt, ...);
bool Invoke(const char* ppathToMethod, const char* pargFmt, ...);
Description

Invoke calls an ActionScript method on the movie clip. There are two different approaches to passing data into Invoke:

  • Using an array of Value objects (slightly more efficient).
  • Using a format string followed by a variable argument list.

Return values are stored in Value object, with potential conversion to UTF-8 strings or other types. 

Use case (1):

   Scaleform::GFx::Value args[3], result;
   args[0].SetNumber(i);
   args[1].SetString("test");
   args[2].SetNumber(3.5);
   pMovie->Invoke("path.to.methodName", &result, args, 3);

Use case (2):

   pmovie->Invoke("path.to.methodName", "%d, %s, %f", i, "test", 3.5);

In the second case, Invoke takes arguments as a variable argument list described by a format string. 

The printf style format string describes arguments that follow in the same order; it can include commas and whitespace characters that are ignored. Valid format arguments are:

%u 
Undefined value, no argument required. 
%d 
Integer argument. 
%s 
Null-terminated char* string argument. 
%ls 
Null-terminated wchar_t* string argument. 
%f 
Double argument. 
%hf 
Float argument, only in InvokeArgs

Sample use:

   pmovie->Invoke("path.to.methodName", "%d, %s, %f", i, "test", 3.5);

In some cases target ActionScript functions may not be yet available at the time Invoke is called on them from C++. This may happen if the functions are created in timeline frames that have not yet been executed or within nested objects that have not yet been created. To avoid this problem we recommend putting most of the C++ interface functions within frame 1 of the root movie clip, and then either calling Advance(0) before they are accessed or passing initFirstFrame argument value of 1 to MovieDef::CreateInstance. Doing so will make sure that frame 1 tags have executed and all of the variables/functions created by that frame are available.

Parameters
Parameters 
Description 
Value * presult 
Holder for the return value from the called method. presult can be null if no return value is desired. 
const Value* pargs 
An array of arguments that will be passed to the method. 
unsigned numArgs 
Number of arguments that will be passed to the method. 
const char* pargFmt 
The format string describing the arguments that will be passed to the method. 
pmethodName 
Name of the method to call, with a possible namespace syntax to access methods in the nested objects and movie clips. 
Return Value

True if the method was invoked otherwise false.