Passing additional parameters into SWFLoader

Recommended Posts

I swear I saw how to do this a while ago - but I have searched the forums to no avail, maybe someone can offer some help.


Im using loadermax to read an XML file of SWFLoaders.

If I use the setting of maxconnections of 1 things load sequentially and all is good.

I store the loader names in an array (using array.push( in the child complete function and play them as needed later on


However If I set it to max connections of 3 - some complete loading before others, and the array ends up out of order. An easy way around this is to just add an index to each loader.


Right now one of the XML nodes look like this :


What I would like to do is this :

Then be able to read that index variable in the child complete function.

(The work around Im using right now is to just parse the name at the _ and use the number as the index - but Id like to remove that constraint.)




Share this post

Link to post
Share on other sites

A few comments:


1) You can getChildren() on the XMLLoader anytime which returns an array of the child loaders that it discovered/parsed in the XML. Those will be in order (it doesn't care if load="true" or not). So the index would correspond to the placement in the array of course. If you've got stuff nested inside nodes, etc., that's fine too - you can just get that particular LoaderMax instance by name and then getChildren() on that LoaderMax. Like if your XML was:

And let's say you wanted to get the children (in order) of queue2. You'd do:

var queue2Children:Array = LoaderMax.getLoader("queue2").getChildren();


2) Or, you can add extra data to your nodes in the XML and it will automatically get added to its "vars" property...


Then, you can get the index in ActionScript like:


var index:int = int( LoaderMax.getLoader("swf1").vars.index );


Notice I cast it as an int() because by default, any extra values parsed in the XML will be Strings.


Does that help?

Share this post

Link to post
Share on other sites

Yup - exactly what I was looking for - It was the referencing it via vars that was jacking me up. Exactly what I needed.




Share this post

Link to post
Share on other sites

Hi Jack! I know it is an old post... But can you help me? Maybe it´s usefull to another mate still doing AS3...

It works perfect in my proyect but... What if I wanted to dynamically change  param1 and param2, after they are loaded?

I have tried but haven't succeed on updating the vars!  Cheers! Robert.

Share this post

Link to post
Share on other sites

HI Robert,


It isn't clear to me exactly what you are trying to do. 

if you have custom parameters in your XMLLoader nodes they will get attached to the vars object for the loaders.

Please read the XMLLoader docs where the 4th code snippet describes how the "description" attribute is placed on the VideoLoader and then later read via loader.vars.description. You should be able to read and write any property of the vars object.

Share this post

Link to post
Share on other sites
Hi Carl!
Thanks for your reply!
Ok I wasn't clear enough...
I´m trying to pass and update a variable to a swf loaded by SWFLoader.
For instance update a text field, included in the loaded swf.
It works if the swf is loaded in the standard way. This is what I wrote:


var Pisadaloader: SWFLoader = new SWFLoader("assets/Pisada_mc.swf", {
name: "PisadaMc",
alpha: 0,
estimatedBytes: 1000,
container: pisada_null_mc,
width: 720,
x: 0,
y: 580,
autoPlay: true
addChildAt(Pisadaloader.content, 1);
param1 = myXML.VIDEO.@NUMTXT;
param2 = myXML.VIDEO.@NUM;
this.Pisadaloader.Titulo_text.text = Titulo;
this.Pisadaloader.SubTitulo_text.text = SubTitulo;

Share this post

Link to post
Share on other sites

Ok. The example you just provided showed how to update variables (or text in a TextField) after the swf is loaded.

What do you need to do differently?

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.