rob_v

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(event.target.name) 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.)

 

Thanks

Rob

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.

 

Thanks

-Rob

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 http://greensock.com/asdocs/com/greensock/loading/XMLLoader.html 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);
Pisadaloader.load();
Titulo = myXML.VIDEO.@TITULO;
SubTitulo = myXML.VIDEO.@SUBTITULO;
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
On 03/08/2016 at 2:15 PM, Carl said:

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?

 

Hi Carl,  sorry for this old thread, but I am not able to pass arguments to my SWF by loader. Can you help me please?

 

My AS3 code:

var mySwfLoader:SWFLoader = new SWFLoader(path, {name:'swf', container:this, width:stage.stageWidth, height:stage.stageHeight, alpha:0, bgColor:"0x000000", autoDispose:false, onComplete:function(event:LoaderEvent){
	mySwfLoader.item1.text = 'TEST THIS';	
	timeline.add(TweenLite.fromTo(event.target.content, 2, {alpha:0, ease: Power0.easeOut}, {alpha:1, ease: Power0.easeOut}),"+="+1);
}
});

 

My .FLA and .SWF to test this:

https://www.dropbox.com/sh/ecihnnzgsvpw8dr/AABQuLXV9aXfWgxeVJb8gZ9Ia?dl=0

 

The SWF is loaded and showed correctly, but I can not change the text of the SWF.

 

Thanks a lot Carl. :)

Share this post


Link to post
Share on other sites

Hi lwmirkk,

 

Sorry but we really don't have a lot of time to be supporting the old AS3 loader stuff.

From looking at your code it looks like you are thinking that the mySwfLoader has a TextField on it called "item1".

 

mySwfLoader.item1.text = 'TEST THIS';    

 

I'm gussing item1 is in the actual swf you loaded so try targeting the rawContent of the SWFLoader like

 

mySwfLoader.rawContent.item1.text = 'TEST THIS';    

 

https://greensock.com/asdocs/com/greensock/loading/core/DisplayObjectLoader.html#rawContent

 

 

  • Thanks 1

Share this post


Link to post
Share on other sites
On 09/04/2018 at 2:54 PM, Carl said:

Hi lwmirkk,

 

Sorry but we really don't have a lot of time to be supporting the old AS3 loader stuff.

From looking at your code it looks like you are thinking that the mySwfLoader has a TextField on it called "item1".

 

mySwfLoader.item1.text = 'TEST THIS';    

 

I'm gussing item1 is in the actual swf you loaded so try targeting the rawContent of the SWFLoader like

 

mySwfLoader.rawContent.item1.text = 'TEST THIS';    

 

https://greensock.com/asdocs/com/greensock/loading/core/DisplayObjectLoader.html#rawContent

 

 

 

Thanks a lot Carl. =)

 

I use AS3 greensock in my desktop app (adobe air).

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.