• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

How can I transfer an object from jsfl to as3?

Contributor ,
Feb 16, 2023 Feb 16, 2023

Copy link to clipboard

Copied


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

TOPICS
ActionScript , Code , Exchange extensions

Views

531

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Engaged , Feb 16, 2023 Feb 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 );
...

Votes

Translate

Translate
Community Expert ,
Feb 16, 2023 Feb 16, 2023

Copy link to clipboard

Copied

use the same

 

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 16, 2023 Feb 16, 2023

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Feb 16, 2023 Feb 16, 2023

Copy link to clipboard

Copied

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 1998
Member of Flanimate Power Tools team - extensions for character animation

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Feb 16, 2023 Feb 16, 2023

Copy link to clipboard

Copied

LATEST

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines