2013-04-25 46 views
-1

我想加载stage.load阶段与函数()4.3.3 kineticjs但没有这样的函数使用Kinetic.Node.create。我不知道如何使用这个功能,有人可以解释它是如何使用的。非常感谢你加载json动力学4.3.3

+0

请提供代码示例 – janex 2013-04-25 19:38:03

回答

0

创建从JSON阶段并不复杂:

  1. 下载序列化JSON阶段。
  2. 水合物var stage = Kinetic.Node.create(myJSON, 'container');

这里的阶段是一些示例代码:

// Use jQuery to call to your server and retrieve 
// the JSON representation of your KineticJS stage 
// jQuery make calling JSON easy, but... 
// Alternatively, you can use straight javascript--google ;) 
$.ajax({ 
    type: "GET", 
    dataType: "json", 
    url: 'http://www.yourSite.com/yourStageInJSON.json', 
    success: successHandler, 
    error: errorHandler 
}); 

// this is called when your json-stage has been downloaded 
function successHandler(myJSON){ 
    // use the downloaded json to create the stage 
    // "container" is just the normal KineticJS container div 
    var stage = Kinetic.Node.create(myJSON, 'container'); 
} 

// this is called if there was a problem with the download 
function errorHandler(){ 
    alert("Something has gone horribly wrong--call somebody!"); 
} 

如果你想看到什么序列化JSON的舞台看起来可以序列现有的阶段是这样的:

var json = stage.toJSON();