使用数组填充文本字段

时间:2014-07-16 17:09:13

标签: json actionscript-3 flash

我有这个textFields

名称,描述。

我有这个阵列。

{"id":3157,"name":"Zhonya's Hourglass","gold":{"base":500,"total":3260,"sell":2282,"purchasable":true},"description":"<stats>+120 Ability Power<br>+50 Armor  </stats><br><br><active>UNIQUE Active - Stasis:</active> Champion becomes invulnerable and untargetable for 2.5 seconds, but is unable to move, attack, cast spells, or use items during this time (90 second cooldown).","sanitizedDescription":"+120 Ability Power +50 Armor UNIQUE Active - Stasis: Champion becomes invulnerable and untargetable for 2.5 seconds, but is unable to move, attack, cast spells, or use items during this time (90 second cooldown).","colloq":"zhg;zonyas","plaintext":"Activate to become invincible but unable to take actions","depth":3,"from":["3191","1058"],"tags":["Armor","SpellDamage","Active"],"maps":{"10":false,"8":false},"image":{"full":"3157.png","sprite":"item1.png","group":"item","x":384,"y":144,"w":48,"h":48},"stats":{"FlatArmorMod":50.0,"FlatMagicDamageMod":120.0}}

如何使用name:和description填充每个字段:不使用数组[index]?

我尝试使用dataProvider,但我不知道如何引用名称或描述

1 个答案:

答案 0 :(得分:0)

你拥有的只是一个对象(或者如果它是从外部源加载的字符串,它是JSON),你可以像访问任何对象一样访问属性:

var data:Object = JSON.decode(YOUR_JSON_STRING); //use this line if it's a string
var data:Object = {"id":3157,"name":"Zhonya's Hourglass","gold":{"base":500,"total":3260,"sell":2282,"purchasable":true},"description":"<stats>+120 Ability Power<br>+50 Armor  </stats><br><br><active>UNIQUE Active - Stasis:</active> Champion becomes invulnerable and untargetable for 2.5 seconds, but is unable to move, attack, cast spells, or use items during this time (90 second cooldown).","sanitizedDescription":"+120 Ability Power +50 Armor UNIQUE Active - Stasis: Champion becomes invulnerable and untargetable for 2.5 seconds, but is unable to move, attack, cast spells, or use items during this time (90 second cooldown).","colloq":"zhg;zonyas","plaintext":"Activate to become invincible but unable to take actions","depth":3,"from":["3191","1058"],"tags":["Armor","SpellDamage","Active"],"maps":{"10":false,"8":false},"image":{"full":"3157.png","sprite":"item1.png","group":"item","x":384,"y":144,"w":48,"h":48},"stats":{"FlatArmorMod":50.0,"FlatMagicDamageMod":120.0}};

nameTextField.text = data.name;
descriptionTextField.text = data.description

您可能不希望将您的名称称为文本字段name,因为它可能与大多数displayObjects上的现有名称属性冲突。