Skip to main content
Multoman
Inspiring
February 16, 2023
Answered

How can I transfer an object from jsfl to as3?

  • February 16, 2023
  • 3 replies
  • 942 views


I have an object in jsfl:
var obj = {color: 2, fol: “ABC”}
I studied this article: https://community.adobe.com/t5/animate-discussions/connecting-jsfl-array-with-swf/m-p/11056883.

I need to do the same thing, only pass not an array, but an object. I tried using JSON.parse(), but for some reason I got an error

This topic has been closed for replies.
Correct answer Vladin M. Mitov

Hi,

In my opinion the only way to transfer structured data from JSFL to AS (and back) is via JSON.

So, try to check what is the reason to got an error.


As a general workflow: you need to stringify the data on JSFL side, and to parse them back on AS side.
For example:

 

 

 

/* JSFL */

var obj = { color: 2, fol: "ABC" };

var stringifiedData = JSON.stringify( obj ); // You should have JSON class

var jsonstring = swfPanel.call( "receiveJSFLData", stringifiedData );

var retval = JSON.parse( jsonstring );




/* AS */

function receiveJSFLData( json:String ):String{
	
	var data:Object = JSON.parse( json );
	
	// Do your stuff with the data
	
	var retval:Object = {};
	
	return JSON.stringify( retval );
}

 

 

Edit:

Here is a vanilla javascript implementation of the JSON, so you can incorporate it in your code:

https://gist.github.com/atheken/654510



3 replies

Vladin M. Mitov
Vladin M. MitovCorrect answer
Inspiring
February 16, 2023

Hi,

In my opinion the only way to transfer structured data from JSFL to AS (and back) is via JSON.

So, try to check what is the reason to got an error.


As a general workflow: you need to stringify the data on JSFL side, and to parse them back on AS side.
For example:

 

 

 

/* JSFL */

var obj = { color: 2, fol: "ABC" };

var stringifiedData = JSON.stringify( obj ); // You should have JSON class

var jsonstring = swfPanel.call( "receiveJSFLData", stringifiedData );

var retval = JSON.parse( jsonstring );




/* AS */

function receiveJSFLData( json:String ):String{
	
	var data:Object = JSON.parse( json );
	
	// Do your stuff with the data
	
	var retval:Object = {};
	
	return JSON.stringify( retval );
}

 

 

Edit:

Here is a vanilla javascript implementation of the JSON, so you can incorporate it in your code:

https://gist.github.com/atheken/654510



- Vlad: UX and graphic design, Flash user since 1998Member of Flanimate Power Tools team - extensions for character animation
Multoman
MultomanAuthor
Inspiring
February 17, 2023

Vladin, thanks. I used to transmit everything through an array, but over time there became so much data that I already began to get confused.

JoãoCésar17023019
Community Expert
Community Expert
February 16, 2023

Hi.

 

The JSON object is not available in the JSFL API. So you'll have to create (or find) your own stringify and parse methods.

But if the object is too simple, you could just concatenate the keys/values manually in a string.

 

Regards,

JC

kglad
Community Expert
Community Expert
February 16, 2023

use the same

 

var obj:Object={color:2, fol: "abc"};