Utilizzando JSON come config in flashembed di Strumenti di jQuery
-
13-09-2019 - |
Domanda
jQuery Tools ha flashembed che può passare un oggetto JSON come un parametro di configurazione per l'incorporamento di oggetti Flash.Vedere la pagina ufficiale.
Ma non spiega esattamente come ottenere l'oggetto JSON in Flash.E questa è la domanda...Come??
Soluzione 2
HTML e 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>
Nella parte Flash, ho usato Casalib s ' FlashVarUtil. Ma sì, quello che Christopher W. Allen-Poole ha detto (loaderInfo.parameters.myJsonObj
) farà il lavoro troppo. (Fino votato per questo)
Sarà un String
in JSON, che è la parte non riuscivo a capire quando la domanda.
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
Altri suggerimenti
Dipende se si è in AS2 o AS3.Credo AS2 semplicemente imposta le variabili sulla _root, ma potrei sbagliarmi.In AS3, è necessario andare alla radice.loaderInfo.i parametri oggetto.Tutte le variabili vengono memorizzate in coppie chiave/valore.
Ad esempio:
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