I am readin in a XML file containg a personal chart structure in the form of a
Spider Chart. So I read through the XML structure and dynamically attach MC's
with attachMovie and then use recursive function calls to produce all the
children of each node of the spider diagram. Each MC that has children I assign
a variable called children to hold an array of them. All's weel but when I
allow one frame to go by and then try and read the children array it's empty!
All other regular variables I have assigned to the same MCs are there. I know
when you assign an array to a MC it is passed by reference and not by value. So
if my orginal loop variables are gone that where holding references to these
MCs would this cause any array data to go also?
So here is the code in the MC I am attaching
// set by parent
var children:Array=
var angle:Number
var name:String
var title:String
name_txt.autoSize=true
name_txt.text=name
title_txt.autoSize=true
title_txt.text=title
And this is how I pass the data into it,
first from the XML object callback
_global.xmlData
// Callback from XML_loader component
XML_finished=function(aNodes:Object){
_global.xmlData=aNodes
//trace(xmlData)
// success so lets move on
this.nextFrame()
}
I have previously set up some parent and subparent clips and then I call this
routine with the MC name subParent
// Recursive function that reads each childs children parameter and traverses
down it's family line calling itself each time to build the family tree
positionSubSubParents=function(aMc:MovieClip){
var aChildren:Array=aMc.children.concat() // read the children list from the
parent MC
var aMenuCount=aChildren.length
if (aMenuCount==0){ // if this node has no children then exit
return 0
}
var subs:Array=
var aCentreX:Number=aMc._x
var aCentreY:Number=aMc._y
var itemGap=15
var startAngle:Number=aMc.angle -((aMenuCount/2)*itemGap)
var circum:Number=180
var quad=whichQuad(aMc.angle)
var xIndent:Number=aCentreX
var yIndent:Number=aCentreY
var myLevel:Number
for (var i=0;i<aMenuCount;i++){
myLevel=this.getNextHighestDepth()
subs=attachMovie("item",("item_"+mcCount),myLevel)
mcCount++
subs.bkgColour=0x99cc00 // light green
subs.name=aChildren.attributes.NAME
subs.title=aChildren.attributes.TITLE
subs.children=aChildren.childNodes
switch (quad){
case 1:
startAngle=aMc.angle -((aMenuCount/2)*itemGap)
angle=startAngle+(i*itemGap)
subs.angle=angle
subs._x=aCentreX+ 100 +Math.cos(degToRad(angle)) * circum
subs._y=aCentreY+ Math.sin(degToRad(angle)) * circum
break;
case 2:
startAngle=90 -((aMenuCount/2)*itemGap)
angle=startAngle+(i*itemGap)
subs.angle=angle
subs._x=xIndent
subs._y=yIndent+50+(i*50)
break;
case 3:
startAngle=180 -((aMenuCount/2)*itemGap)
angle=startAngle+(i*itemGap)
subs.angle=angle
subs._x=aCentreX- 100 +Math.cos(degToRad(angle)) * circum
subs._y=aCentreY+ Math.sin(degToRad(angle)) * circum
break;
default: // 4
startAngle=270 -((aMenuCount/2)*itemGap)
angle=startAngle+(i*itemGap)
subs.angle=angle
subs._x=xIndent
subs._y=yIndent-50-(i*50)
break;
}
// call this function again recursively if this node has children
if (subs.children.length<>0){
positionSubSubParents(subs)
}
}
return 1
};
MCR - 31 Mar 2006 18:21 GMT
Just created a much simpler example of this problem.
Download here www.mmcr.co.uk/arrayTest.zip
Any ideas what I'm doing wrong here???
Many thanks for any help
Kevin