• Using attributes of an XML file for a var Name? (AS 3.0)
    4 replies, posted
I've got a simple XML file that I'm using to load Objects for my Box2D Engine through a parser. It looks like this: [code]<object_list> <!--Shapes... Collisions... Finish documenting this. --> <shapes> <!--Add other attribues to this tag... Density, Sprite, etc. --> <shape name="TestShape1" sprite="TestSprite1" alpha="1.0" scaleX="1.0" scaleY="1.0" friction="0.5" restitution="0.5" density="0.0" isSensor="false" > <vertex>0,0</vertex> <vertex>50,0</vertex> <vertex>60,200</vertex> <vertex>50,400</vertex> <vertex>0,400</vertex> </shape> <shape name="TestShape2" sprite="TestSprite2" alpha="1.0" scaleX="1.0" scaleY="1.0" friction="0.5" restitution="0.5" density="0.0" isSensor="false" > <vertex>2,1</vertex> <vertex>2,2</vertex> <vertex>2,3</vertex> </shape> </shapes> </object_list> [/code] Now to implement it into my function, I call: var testObject:ArbiActor = new ArbiActor( _cameraRef, new Point( 50, 50 ), testShapesArray, TestSprite1 , 1.0, 1.0, 1.0, 0.5, 0.5, 0.0, false ); Most of those parameters will be filled with loaded from the XML. However, I wish to make the 'testObject:ArbiActor = New ArbiActor' -- I want it to get it's name from the @name attribute in my XML file. Is this possible? If you need the source for ArbiActor I can provide that, maybe there is a different way to implement it.
I don't think I quite know what you mean, however what you can do is instead of creating dynamic variable names, then simply create an object. In an object you can assign "variable names" like arrays in PHP var objContainer:Object = new Object(); var objMyObject:Object = new b2Body(); var strMyObject:String = "TestShape1"; objContainer[strMyObject] = objMyObject; trace(objContainer["TestShape1"]);
Now I'm the confused one. I think I might need to re-structure this program because: To create an object I need to feed it X/Y coordinates of where it will go. I was going to load the Objects into the engine first, and then load levels (Which were just placements of the physics objects). However I can't think of a good way to do this now. I can create a new Object via the new ArbiActor. This creates an instance of the physics object. Maybe if I used the ObjectLoader function to load the objects into an Array from the XML, and then in the level-load function had an 'ArrayID' which corresponded to it's position in the Array from ObjectLoader and THAT called the create function would work better. I'm not quite sure anymore... I think I need someone with a better idea of what I need to do to help me. :v:
Whelp this is terminally fucked, gonna re-design a loading system.
It is very possible, I've done it an it isn't hard at all. [url]http://www.kirupa.com/web/xml/index.htm[/url]
Sorry, you need to Log In to post a reply to this thread.