 
 	r = ''
 
+	for child in getByType(obj.body, OBJECT)
+		r += stringAttributes child
+
 	for attribute in getByType(obj.body, ATTRIBUTE)
 		r += stringAttribute attribute, [obj]
-
-	for child in getByType(obj.body, OBJECT)
-		r += stringAttributes child
 
 	r
 

	if getByType(obj.body, ID).length > 0
		ids[obj.id] = true

	isLocal = Renderer[obj.name.split('.')[0]]?
	properties = getEachProp(getByType(obj.body, PROPERTY), 'name')
	signals = getEachProp(getByType(obj.body, SIGNAL), 'name')

	args = []
	args.push "properties: #{JSON.stringify properties}" if properties.length
	args.push "signals: #{JSON.stringify signals}" if signals.length
	if args.length
		args = "{#{args.join ', '}}"

	decl = if isLocal then "new #{obj.name}" else "#{obj.name}"
	r = "var #{obj.id} = #{decl}(#{args or ''});\n"

	for child in getByType(obj.body, OBJECT)
		r += stringObject child
		r += "if (#{child.id} instanceof Item){ #{child.id}.parent = #{obj.id}; }\n"

	# initialize states
	if getElemByName obj.body, ATTRIBUTE, 'states'
		r += "#{obj.id}.states\n"

	r


			for id, i in elem
				text += ", '#{id}']"

	"[#{text}]"

stringObject = (obj) ->
	assert obj.type is OBJECT, "stringObject: type must be an object"
