Search code examples
flashactionscriptloadactionscript-2

Pass Parameters when loading external swf as2 when pressing corresponding button


There is a code here in this tutorial to load external swf with as2: The code is as follows:

var swfLoader:MovieClipLoader = new MovieClipLoader();
var loadingListener:Object = new Object();

swfLoader.addListener(loadingListener);

loadingBtn_mc.onRelease = function()
{
    swfLoader.loadClip("slides.swf",container_mc);
    this._visible = false;
};

loadingListener.onLoadStart = function(container:MovieClip):Void 
{
    trace("The MovieClip " + container + " started loading");
    loadingProgress_mc._x = 126;
    loadingProgress_mc._y = 135;
};

loadingListener.onLoadProgress = function(container:MovieClip, bytLoaded:Number, bytTotal:Number):Void 
{
    var percentageLoaded:Number = (bytLoaded / bytTotal) * 100;

    loadingProgress_mc.percentage_txt.text = String(Math.floor(percentageLoaded));

    trace("Loading progress = " + String(Math.floor(percentageLoaded)));
};

loadingListener.onLoadComplete = function(container:MovieClip):Void 
{
    trace("The MovieClip " + container + " has completed loading");
    loadingProgress_mc._x = -200;
};

loadingListener.onLoadInit = function(container:MovieClip):Void 
{
    trace("The MovieClip " + container + " has been initialized");
};

loadingListener.onLoadError = function(container:MovieClip, errorCode:String):Void 
{
    trace("Error loading the file. Error code = " + errorCode);
};

To unload swf (once loaded) I added:

    unloadingBtn_mc.onRelease = function()
{
    swfLoader.unloadClip(container_mc);
    //this._visible = false;
};

But How how to pass a parameter to "slides.swf" in swfLoader.loadClip("slides.swf",container_mc); ?

Here is the source file


Solution

  • I think you can do something like...

    swfLoader.loadClip("slides.swf?data1=12345&data2=67890",container_mc);
    

    and then you should be able to access it like so (in slides.swf)...

    var my_data1:String = _level0.data1;
    var my_data2:String = _level0.data2;
    

    Although, its been a while since I've done any AS2 :)