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

Load and display data from JSON file.

Guest
Mar 16, 2014 Mar 16, 2014

So I have this json file with a name demo.json

It is basically a notepad file with text:


{

"type":"Toy",

"animal": "Bear",

"data": {

"name": "Timmy",

"color": "Brown",

"price": "10",

"madein": "USA"

}

}



And I need this data to be loaded and displayed in flash swf file. Maybe there is someone who knows how it could be done?

TOPICS
ActionScript
5.5K
Translate
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
LEGEND ,
Mar 16, 2014 Mar 16, 2014

1. Use URLLoader to load this file.

2. Once it is loaded use JSON class to parse received file.

Here is JSON documentation:

http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/JSON.html

Translate
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
Guest
Mar 16, 2014 Mar 16, 2014

Thank You!

Will this be correct ?

//import Jason.as class

import com.adobe.serialization.json.JSON

var loader:URLLoader = new URLLoader();

var request:URLRequest = new URLRequest();

 

request.url = "demo.json";

loader.load(request);

loader.addEventListener(Event.COMPLETE, decodeJSON);

Translate
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
LEGEND ,
Mar 16, 2014 Mar 16, 2014

Yes, it look right (although incomplete).

Translate
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
Guest
Mar 16, 2014 Mar 16, 2014

Ok, so I make 6 dynamic text fields in AS3 with instance names

type.txt

animal.txt

name.txt

color.txt

price.txt

madein.txt

and I need the data from JSON file to be displayed into those text fields.

Coud You please tell me what would be the correct code for that?

Translate
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
LEGEND ,
Mar 16, 2014 Mar 16, 2014
LATEST

1. Do not use special characters in variables names (remove dots from instances names).

2. What did you do so far? Do you know how to create text fields and write values into them?

Translate
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