Copy link to clipboard
Copied
Hi,
Can you help me.
Details of 4 ID are visible by pressing button 1. I have shown these details through a text window (instance name: txt) and I have a back button.It is working fine.
If what I need
The details in the ID 1 should display at the pull of by button1.
The details in the ID 2 should display at the pull of by button2.
The details in the ID 3 should display at the pull of by button3.
The details in the ID 4 should display at the pull of by button4
Please help me.sorry not proper communication.
JSON file.
"data":
[
{"id":"1","name":"John Deo","class":"Four5",
"mark":"75","sex":"male"},
{"id":"2","name":"Max Ruin","class":"Three5",
"mark":"85","sex":"male"},
{"id":"3","name":"Arnold","class":"Three5",
"mark":"55","sex":"male"},
{"id":"4","name":"Krish Star","class":"Four5",
"mark":"60","sex":"male"}
]
}
JSON file script
var that = this;
this.json = {};
this.loadJson = function(url)
{
var queue = new createjs.LoadQueue(true);
queue.on("fileload", that.onJsonLoaded, that);
queue.on("error", that.onJsonLoadError, that);
queue.loadFile({id:"json", src:url});
}
this.onJsonLoaded = function(e)
{
that.json = e.target.getResult("json");
that.setText();
}
this.onJsonLoadError = function(e)
{
console.log(e);
}
this.setText = function()
{
var data = that.json.data;
for (var i = 0, total = data.length; i < total; i++)
that.txt.text = that.txt.text + "\n" + data[i].id + ", " + data[i].name + ", " + data[i].class + ", " + data[i].mark + ", " + data[i].sex;
}
this.loadJson("json_id.json");
button1 Code(frame 1)
this.button_1.addEventListener("click", fl_ClickToGoToAndPlayFromFrame_6.bind(this));
function fl_ClickToGoToAndPlayFromFrame_6()
{
this.gotoAndPlay(5);
}
Back Button code(frame 10)
this.button_3.addEventListener("click", fl_ClickToGoToAndStopAtFrame_6.bind(this));
function fl_ClickToGoToAndStopAtFrame_6
{
this.gotoAndPlay(5);
}
Regards,
saravananN
Copy link to clipboard
Copied
if you want variables to be defined on other timeline frames, you should NOT make them local to the frame where they are defined. ie,
var data = whatever
localizes data to the frame that contains the above line.
that.data = whatever defines it throughout the timeline.
further if you use
function f(){
var data = whatever;
}
data is localized to f() and not even defined in the frame after f() executes.
ie use:
this.setText = function()
{
that.data = that.json.data;
for (var i = 0, total = data.length; i < total; i++)
that.txt.text = that.txt.text + "\n" + data[i].id + ", " + data[i].name + ", " + data[i].class + ", " + data[i].mark + ", " + data[i].sex;
}
p.s. your json file is malformed. there should be a left curly bracket before "data".