Skip to content

Instantly share code, notes, and snippets.

@intafon
Last active January 1, 2016 13:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save intafon/8149251 to your computer and use it in GitHub Desktop.
Save intafon/8149251 to your computer and use it in GitHub Desktop.
Shows how a swf loaded by an html embedded swf can access the flashvars.
package
{
import flash.display.Sprite;
import flash.display.Loader;
import flash.net.URLRequest;
/**
* Loads SwfB in the same way a swf usually loads a swf.
*/
public class SwfA extends Sprite
{
public function SwfA()
{
var flashVars:Object = root.loaderInfo.parameters;
var s:String = this + "\n";
for (var i:String in flashVars) {
s += i + " = " + flashVars[i] + "\n";
}
trace("Main Client FlashVars:" + s);
var ldr:Loader = new Loader();
var urlReq:URLRequest = new URLRequest("SwfB.swf");
ldr.load(urlReq);
addChild(ldr);
}
}
}
package
{
import flash.display.Sprite;
import flash.events.Event;
/**
* This class is loaded by SwfA and waits until it has been added to the stage
* in order to obtain the flash vars from the stage.loaderInfo.
*/
public class SwfB extends Sprite
{
public function SwfB()
{
addEventListener(Event.ADDED_TO_STAGE, onAddedToStage);
}
private function onAddedToStage(e:Event):void
{
var flashVars:Object = stage.loaderInfo.parameters;
var s:String = this + "\n";
for (var i:String in flashVars) {
s += i + " = " + flashVars[i] + "\n";
}
trace("Loaded Swf FlashVars when Added to Stage: " + s);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment