Announcements
The Scaleform forum is now read-only. Please head to the Gamedev site for product support.
Scaleform Forum (Read Only)
Scaleform enables developers to leverage the power of the Adobe® Flash® tool set to create powerful user interface environments for video games.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Is it possible to pass ByteArray?

6 REPLIES 6
Reply
Message 1 of 7
FrankFloor84
597 Views, 6 Replies

Is it possible to pass ByteArray?

Is it possible to pass a ByteArray from Flash to C++ and back. We are using the Obj-C PlayerIO library for multiplayer. Their plugin takes and gives NSData that is supposed to represent a ByteArray, but I am not sure how to convert the values. On making the AS call, the Obj Value shows as VT_Object. On receiving NSData from the server, is it possible to convert this back to VT_Object type to send back to AS?

6 REPLIES 6
Message 2 of 7
wxneypar
in reply to: FrankFloor84

Great question, could you figure it out? It could solve my issue too if there's a possibility to do this and then create a bitmap from that byteArray with flash.

It seems that no one from the dev team reads our questions lol

 

Cheers

 

Pedro

Message 3 of 7
FrankFloor84
in reply to: wxneypar

If you are just looking to get an image from Obj-C to Flash, we handle that by passing it as a base64 string. Here's some example code that we use to asynchronously load an image from a URL into Flash.

 

//============================================================================//
// C++ Handler
void F84UtilitiesHandler::Call(const Params& params)
{
	int method = int(params.pUserData);
	switch(method)
	{
		case METHOD_LoadImageFromURL:
			LoadImageFromURL(params.pArgs[0].GetString(), params.pArgs[1]);
			break;
	}
}
//============================================================================//
// C++ Handler
void F84UtilitiesHandler::LoadImageFromURL(const char* url, GFx::Value& success)
{
	// In order to save C++ objects in the block below
	__block GFx::Value successFunc = success;
	
	[utilitiesManager loadImageFromURL:[NSString stringWithUTF8String:url]
							   success:^(NSString* base64Image)
	{
		GFx::Value args[1];
		args[0].SetString([base64Image UTF8String]);
		successFunc.InvokeSelf(NULL, args, 1);
	}];
}
//============================================================================//
// Obj-C Class
- (void)loadImageFromURL:(NSString*)url
				 success:(void(^)(NSString* base64Image))success
{
	NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:url]];
	[NSURLConnection sendAsynchronousRequest:request
									   queue:[NSOperationQueue mainQueue]
						   completionHandler:^(NSURLResponse* response, NSData* data, NSError* error)
	{
		NSString* base64Image = [data base64Encoding];
		success(base64Image);
	}];
}
//============================================================================//
// Actionscript
public function loadAvatarFromURL(url:String):void
{
	F84UtilitiesInterface.instance.loadImageFromURL(url, function(base64Image:String):void
	{
		var byteArray:ByteArray = Base64.decodeToByteArray(string);
		var loader:Loader = new Loader();
		loader.contentLoaderInfo.addEventListener(Event.INIT, function(e:Event):void
		{
			var bitmapData:BitmapData = new BitmapData(loader.width, loader.height);					
			bitmapData.draw(loader);
			
			var bitmap:Bitmap = new Bitmap(bitmapData);
			bitmap.width = AVATAR_WIDTH;
			bitmap.height = AVATAR_HEIGHT;
			avatarSpaceMovieClip.addChild(bitmap);
		});				
		loader.loadBytes(byteArray);
	}
}
//============================================================================//

 

Message 4 of 7
wxneypar
in reply to: FrankFloor84

I'm working on Android, but the flow would be to to get the image in C++ and base 64 encode those bytes in a string variable and pass it to Actionscript, then in AS base64 decode them to bytes and create the image? Am I right? Any known issues with some of this flow in Android?

 

You are being very helpful, thank you!

Message 5 of 7
FrankFloor84
in reply to: wxneypar

I haven't written the Android plugin for this yet, but the flow should be the same. I think the bytes you are encoding must be either in JPEG or PNG format before you convert them to base64. I would take a guess that this would be the correct way on Android to get the base64 string:

 

http://stackoverflow.com/questions/17191301/android-image-to-base64-string-issue

Message 6 of 7
wxneypar
in reply to: FrankFloor84

I will be trying to implement this tonight or tomorrow, I really appreciate your help, huge thanks

Message 7 of 7
FrankFloor84
in reply to: FrankFloor84

I ended up just handling this with strings, but I just found out that you can read and write to ByteArrays in C++ with ReadFromByteArray and WriteToByteArray

 

GFx::Value byteArrayValue = params.pArgs[0];
int byteArraySize = byteArrayValue.GetByteArraySize(); UByte* byteArray = (UByte*)malloc(byteArraySize * sizeof(UByte)); byteArrayValue.ReadFromByteArray(byteArray, byteArraySize); NSData* data = [NSData dataWithBytes:byteArray length:byteArraySize]; free(byteArray);

 

Guess I'll have to go and rewrite that whole system Smiley Tongue

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report