Skip to main content
Multoman
Inspiring
Feb 16, 2023 4:41 PM UTC
Answered

How can I transfer an object from jsfl to as3?


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 is closed to new replies. Start a new post to keep the conversation going.
Vladin M. Mitov
Vladin M. MitovCorrect answer
Inspiring
Feb 16, 2023 5:38 PM UTC

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

4 replies

Vladin M. Mitov
Vladin M. MitovCorrect answer
Inspiring
Feb 16, 2023 5:38 PM UTC

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



Translate
- Vlad: UX and graphic design, Flash user since 1998Member of Flanimate Power Tools team - extensions for character animation
Multoman
MultomanAuthor
Inspiring
Feb 17, 2023 5:18 AM UTC

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.

Translate
JoãoCésar17023019
Community Expert
Community Expert
Feb 16, 2023 5:35 PM UTC

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

Translate
kglad
Community Expert
Community Expert
Feb 16, 2023 4:49 PM UTC

use the same

 

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

Translate