009 從Flash到C#發送陣列 ( Invoke help - arrays to flash)

Post date: 2012/11/22 上午 10:21:13

Invoke help - arrays to flash

Rate this thread

Permlink of this thread Subscribe to this thread

avatar
  • rjmyth
  • Posted: 2012-10-22 8:59 AM
  • Total Posts: 14
  • Joined: 18 September 2012 06:25 AM

Howdy

Wanted some help using the invoke function.

I need to send an array of strings (using String[] myStrings = ["First", “Second"]; etc ), I would also similarly like to send ints and/or uints in the same way.

The Value variable type is pretty confusing and I haven’t been able to figure out a method besides my bad way. This involves using a loop to call invoke on every myString.length and create the array in as3 using this data, and finally invoking another function after these have finished. This seems really messy so please let me know if there’s a better way I am missing.

Cheers

Ricky

Passing Arrays to Flash from C# is not currently possible, but this feature is being worked on for a future patch. However, have you tried something like this?

C# Code Snippet

Value[] args = { new Value("testing1", MovieID), new Value("testing2", MovieID), new Value(true, MovieID), new Value(52, MovieID) };
Value retVal = new Value();
myMovieRef.Invoke("myAS3Function", args, ref retVal);

ActionScript 3 Code Snippet

public function myAS3Function(... args):void {
    for (var i:int = 0; i < args.length; i++) {
        trace(args[i]);
    }
}

Author: MatthewDoyleArt

Replied: 2012-10-24 6:03 AM

avatar
  • rjmyth
  • Posted: 2012-10-24 6:56 AM

That’s just sending alot of parameters. But my array is compiled elsewhere and is varying length anything from 0-hundreds so I would need to send an actual array if possible.

avatar
  • rjmyth
  • Posted: 2012-10-24 10:34 PM

Hey Matt, thanks for the reply. I did search before posting this thread and couldn’t find a similar issue, but searching today for the opposite issue of receiving an array from flash… i found this thread which didn’t come up in the other search results…

http://area.autodesk.com/for...commit-an-array-to-flash/

to I can rearrange this to get the solution I need, thanks :P and sorry for the re post of the problem when its solved already.

While I’m here though, how about any insight into the other problem. I’m trying to send an array from flash, into an int[] list of c# but I’m not sure what paramater variable type to use.

To send an Array from ActionScript/Flash and read it in C#, use something like this:

ActionScript 3 Code Snippet

var myArray:Array = ["someString", 23, false];
ExternalInterface.call("myUnityFunction", myArray);

C# Code Snippet

public void myUnityFunction(Value myArray){
    for (uint i = 0; i < myArray.GetArraySize(); i++ ) {
        Debug.Log (myArray.GetElement(i));
    }
}

Author: MatthewDoyleArt

Replied: 2012-10-25 2:27 AM

/img/forum/dark/default_avatar.png

Many thanks. All sorted :)

Author: rjmyth

Replied: 2012-10-25 6:29 AM