jQuery Tools has flashembed which can pass a JSON object as a config parameter to the embedding Flash object. See the official page.
But it does not tell exactly how to get the JSON object in Flash. And that's the question... How??
jQuery Tools has flashembed which can pass a JSON object as a config parameter to the embedding Flash object. See the official page.
But it does not tell exactly how to get the JSON object in Flash. And that's the question... How??
That depends on whether you are in AS2 or AS3. I believe AS2 simply sets the variables on the _root, but I could be mistaken. In AS3, you will need to go to your root.loaderInfo.parameters object. All of the variables are stored there in key/value pairs.
Eg:
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
HTML and 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>
In the Flash part, I used Casalib's FlashVarUtil. But yes, what Christopher W. Allen-Poole said (loaderInfo.parameters.myJsonObj
) will do the job too. (up voted for that)
It will be a String
in JSON, that's the part I couldn't figure out when asking the question.
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