Jump to content
Search Community

Read custom attributes in XML - SWFLoader Node

suppenhuhn test
Moderator Tag

Recommended Posts

Hello!

 

I'm using LoaderMax to load multiple SWFs via XML into my main SWF. I have some arrays for different SWF-classes ( A,B,C)

The SWFLoader node contains the custom attribute "myclass":

....
<SWFLoader name="myName" url="swf/mySWF.swf" myclass="Class-A" load="true" autoPlay="false" centerRegistration="true"  estimatedBytes="112000" />
<SWFLoader name="myName2" url="swf/mySWF2.swf" myclass="Class-B" load="true" autoPlay="false" centerRegistration="true" estimatedBytes="122000" />
<SWFLoader name="myName3" url="swf/mySWF3.swf" myclass="Class-A" load="true" autoPlay="false" centerRegistration="true" estimatedBytes="92000" />
....

Now i'd like to read/check this attribute within the swfCompleteHandler function and push the loaded SWF into the according array:

private var queue:XMLLoader = new XMLLoader("xml/my_glasses.xml",{name:"xmlDoc",
        maxConnections:1,
        estimatedBytes:5000,
        onComplete:queueCompleteHandler,
        onProgress:queueProgressHandler,
        onChildProgress:swfProgressHandler,
        onChildComplete:swfCompleteHandler
        });


private function swfCompleteHandler(event:LoaderEvent):void {
			
			var loadedSWF:ContentDisplay = event.target.content as ContentDisplay;
			var glass:McGlass = new McGlass();
			glasses.push(glass);
			
// HERE I'D LIKE TO CHECK THE CLASS OF THE LOADED SWFs and push it into a array
			
loadedSWF.addChildAt(glass, 0);
			addChild(loadedSWF);

		}

But i have no idea how to do this - can anybody may give an advice?

 

Greetings

Rob

Link to comment
Share on other sites

Thanks for the clear question with the sample code. Very helpful. 

 

Should be fairly straight-forward. Inside your swfCompleteHandler function 

event.target is the SWFLoader that just loaded. That SWFLoader stores all the attributes from the xml node in its vars object. The myclass name for each swf can be accessed with:

event.target.vars.myclass

Try this

private function swfCompleteHandler(event:LoaderEvent):void {


var loadedSWF:ContentDisplay = event.target.content as ContentDisplay;
var glass:McGlass = new McGlass();
glasses.push(glass);


// HERE I'D LIKE TO CHECK THE CLASS OF THE LOADED SWFs and push it into a array


// NEW //
trace( event.target.vars.myclass )
// END NEW //


loadedSWF.addChildAt(glass, 0);
addChild(loadedSWF);


}

For more details the XMLLoader docs mentions this as well as storing more xml-formatted data with each loader: http://api.greensock.com/as/com/greensock/loading/XMLLoader.html (3rd code block)

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...