Looking for a way to make this slimmer - AS3
Hi all. First time poster and novice AS3 / Animate CC user.
I'm pulling data from a JSON file and passing it to text objects on my canvas.
I ran into a problem where some of the values on the JSON file were "null" and was getting a "TypeError: Error #2007: Parameter text must be non-null".
I'm working around this by creating and If statement for each text object and replacing any "null" with "0" string. I'm doing this for each text object and it feels clunky.
The questions: is there a better way to do this?
Here is the function:
//(remainingUserCount_# are the text objects on the canvas)
function processJson(e:Event):void
{
var jsonObject:Object = JSON.decode (e.target.data);
var NullString:String = "0"
//Remaining user count question 1
if (jsonObject.game['questions'][0]['remainingUsersCount'] == null)
{
remainingUsersCount_1.text = NullString
}
else
{
remainingUsersCount_1.text = String(jsonObject.game['questions'][0]['remainingUsersCount'])
}
//Remaining user count question 2
if (jsonObject.game['questions'][1]['remainingUsersCount'] == null)
{
remainingUsersCount_2.text = NullString
}
else
{
remainingUsersCount_2.text = String(jsonObject.game['questions'][1]['remainingUsersCount'])
}
//Remaining user count question 3
if (jsonObject.game['questions'][2]['remainingUsersCount'] == null)
{
remainingUsersCount_3.text = NullString
}
else
{
remainingUsersCount_3.text = String(jsonObject.game['questions'][2]['remainingUsersCount'])
}
}
Thanks!
