Jump to content
Search Community

Passing additional parameters into SWFLoader

rob_v test
Moderator Tag

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

Link to comment
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?

Link to comment
Share on other sites

  • 4 years later...

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.

Link to comment
Share on other sites

  • 1 year later...
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. :)

Link to comment
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
Link to comment
Share on other sites

On 4/9/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. ?

Link to comment
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.
×
×
  • Create New...