【问题标题】:Using JSON as config in flashembed of jQuery Tools在 jQuery Tools 的 flashembed 中使用 JSON 作为配置
【发布时间】:2009-09-22 17:24:41
【问题描述】:

jQuery 工具有 flashembed,它可以将 JSON 对象作为配置参数传递给嵌入的 Flash 对象。见the official page

但它并没有确切说明如何在 Flash 中获取 JSON 对象。这就是问题......如何??

【问题讨论】:

    标签: flash json parameters embed jquery-tools


    【解决方案1】:

    这取决于你是在 AS2 还是 AS3。我相信 AS2 只是在 _root 上设置变量,但我可能弄错了。在 AS3 中,您需要转到您的 root.loaderInfo.parameters 对象。所有变量都以键/值对的形式存储在那里。

    例如:

    myAS2Swf.swf?example=72&other="Quack"
    
    // in the swf:
    trace( _root.example ); // 72
    trace( _root.other   ); // Quack
    
    // in AS3
    
    myAS3Swf.swf?example=42&other="Duck"    
    
    // in the swf:
    trace( root.loaderInfo.parameters.example ); // 42
    trace( root.loaderInfo.parameters.other   ); // Duck
    

    【讨论】:

      【解决方案2】:

      HTML 和 JS:

      <script type="text/javascript" src="js/jquery.tools.min.js"></script>
      <script type="text/javascript">
          $(function(){               
              $("#flashPlacement").flashembed(
                  {
                      src:"Main.swf"
                  },
                  {   //flashvars
                      myJsonObj:
                      {
                          someString:"string",
                          someNumber:123,
                          someOtherObj:
                          {
                              someString:"string2",
                              someNumber:456
                          }
                      }
                  }
              );
              $("#flashPlacement *").show();
          });
      </script>
      

      在 Flash 部分,我使用了Casalib 的 FlashVarUtil。但是,是的,Christopher W. Allen-Poole 所说的 (loaderInfo.parameters.myJsonObj) 也可以完成这项工作。 (对此投赞成票)

      这将是 JSON 格式的 String,这是我在提问时无法弄清楚的部分。

      AS3:

      import com.adobe.serialization.json.JSONDecoder;
      import org.casalib.util.FlashVarUtil;
      import org.casalib.util.StageReference;
      
      StageReference.setStage(stage);
      var jsonString:String = FlashVarUtil.getValue("myJsonObj");
      
      //use as3corelib's JSONDecoder
      //http://code.google.com/p/as3corelib/
      var obj:Object = new JSONDecoder(jsonString).getValue();
      
      //now it can be used like...
      trace(obj.someOtherObj.someString); //output: string2
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2012-01-09
        • 2011-10-17
        • 2017-09-26
        • 1970-01-01
        • 2017-07-03
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多