Groups | Blog | Home
all groups > flash actionscript > december 2005 >

flash actionscript : Actionscript for XML tree menu


S_anctified
12/13/2005 10:04:12 PM
I have a working xml tree menu, but I just want one menu to close when another
is chosen instead of all staying open. It shouldn't be too hard to change, but
this code is above me.

MovieClip.prototype.moveMenu=function()
{
var py=this._y;
var pos_y;
var lastpath=eval(this.lastPath);
if(lastpath!=undefined &&
this.lastPath.substr((this.lastPath.length-6),6)!="titolo")
{
this.onEnterFrame=function()
{
if((lastpath._y+lastpath.h_id)!=this._y)
{
pos_y =lastpath._y+lastpath.h_id;
this._y += (pos_y-this._y)/Obj.velocita;
if(Math.abs(pos_y-this._y)<1)this._y=pos_y;
}
}
}
}
MovieClip.prototype.apriMask=function()
{
this.mask.onEnterFrame=function()
{
this._height+=(this._parent.h_id-this._height)/Obj.velocita;
if(Math.abs(this._parent.h_id-this._height)<1)
{
this._height=this._parent.h_id;
this.onEnterFrame=undefined;
}
}
}
MovieClip.prototype.turnArrow=function()
{
var rotazione;
this._parent.clik ? rotazione=90 : rotazione=0;
this.onEnterFrame=function()
{
this._rotation+=(rotazione-this._rotation)/2;
if(Math.abs(this._rotation-rotazione)<1)
{
this._rotation=rotation;
this.onEnterFrame=undefined;
}
}
}
MovieClip.prototype.apriMenu=function()
{
var path, clip, subClip, thisPath, diff=undefined, disteso=Obj.disteso;
thisPath=this._parent;
clip=new Array();
path=thisPath._parent;
//---------------------- opzione contratto ------
function trovaDiff(diff_p)
{
for(var d_c in diff_p._parent)
{
if(typeof(diff_p._parent[d_c])=="movieclip"
&& d_c!="titolo"
&& d_c!="mask"
&& diff_p._parent[d_c]!=diff_p
&& diff_p._parent!=undefined)
{
if(diff_p._parent[d_c].h_id>Obj.altezza+Obj.inerlinea)
diff=diff_p._parent[d_c].h_id;
diff_p._parent[d_c].h_id=Obj.altezza+Obj.inerlinea;
diff_p._parent[d_c].apriMask();
diff_p._parent[d_c].moveMenu();

diff_p._parent[d_c].titolo.clik=false;
diff_p._parent[d_c].titolo.frec.turnArrow();
}
}
}
if(disteso==false)trovaDiff(thisPath);

function cont_c_subClip(c_s_p)
{
for(var c_c in c_s_p._parent)
{
if(typeof(c_s_p._parent[c_c])=="movieclip"
&& c_c!="titolo"
&& c_c!="mask"
&& c_s_p._parent[c_c]!=c_s_p
&& c_s_p._parent!=undefined)
{
c_s_p._parent[c_c].h_id=Obj.altezza+Obj.inerlinea;
c_s_p._parent[c_c].apriMask();
c_s_p._parent[c_c].moveMenu();
c_s_p._parent[c_c].titolo.clik=false;
c_s_p._parent[c_c].titolo.frec.turnArrow();
cont_c_subClip(c_s_p._parent[c_c].titolo);
}
}
}
if(disteso==false)cont_c_subClip(thisPath);
//-----------------------------------------------
for( var a in path)
{
if(typeof(path[a])=="movieclip" && a!="mask")
{
subClip=new Array();
for( var b in path[a])
{
if(typeof(path[a][b])=="movieclip" && b!="mask")
{
subClip.push(path[a][b]);
}
}
subClip.reverse();
clip.push([path[a], subClip]);
}
}
clip.reverse();


for(var mm=0; mm<clip.length; mm++)
{
if(clip[mm][0]==thisPath)
{
this._parent.h_id*=clip[mm][1].length;
if(diff!=undefined)
{
var vd = this._parent.h_id-diff;
diff = vd;
}

}
var lp = new String(clip[mm-1][0]);
clip[mm][0].lastPath=lp;
clip[mm][0].moveMenu();
clip[mm][0].apriMask();
}

//---------------------------- sistema _h precedenti

function rip_subClip(t,d)
{
pathStr=new String(t);
if((pathStr.substr(pathStr.lastIndexOf(".")+1)).indexOf("box")!=-1)
{
t.h_id+=d-(Obj.altezza+Obj.inerlinea);
t.apriMask();
for(var subx in t._parent)
{
if(typeof(t._parent[subx])=="movieclip" && t._parent[subx]!=t)
{
t._parent[subx].moveMenu();
}
}
var s_t=t._parent;
var s_d=d;
rip_subClip(s_t, s_d);
}
}
var subDist=this._parent.h_id;
rip_subClip(path,(diff==undefined ? subDist :
vd+(Obj.altezza+Obj.inerlinea)));
}
MovieClip.prototype.chiudiMenu=function()
{

var thisPath;
thisPath=this._parent;
//----------------------chiude le precedenti
function rip_subLastClip(ts,l_Dist)
{
var lastDist=ts.h_id;
var newlastDist= l_Dist==undefined ? (lastDist-(Obj.altezza+Obj.inerlinea))
: l_Dist;
pathStr=new String(ts._parent);
if((pathStr.substr(pathStr.lastIndexOf(".")+1)).indexOf("box")!=-1)
{
ts._parent.h_id-=newlastDist;
ts._parent.apriMask();
for(var thisLstPath in ts._parent._parent)
{
if(typeof(ts._parent._parent[thisLstPath])=="movieclip"
&& thisLstPath!="titolo"
&& thisLstPath!="mask")
{
ts._parent._parent[thisLstPath].moveMenu();
}
}
rip_subLastClip(ts._parent,newlastDist);
}
}
rip_subLastClip(thisPath);



//----------------------chiude lo stesso gruppo
thisPath.h_id=Obj.altezza+Obj.inerlinea;
thisPath.apriMask();

for(var thisSubPath in thisPath._parent)
{
if(typeof(thisPath._parent[thisSubPath])=="movieclip"
&& thisPath._parent[thisSubPath]!=thisPath
&& thisSubPath!="titolo"
&& thisSubPath!="mask")
{
thisPath._parent[thisSubPath].moveMenu();
}
}
//----------------------chiude le clip successive
function c_subClip(s_p)
{
for(var c in s_p)
{
if(typeof(s_p[c])=="movieclip"
&& c!="titolo"
&& c!="mask")
{
s_p[c].h_id=Obj.altezza+Obj.inerlinea
s_p[c].titolo.clik=false
s_p[c].titolo.frec.turnArrow()
s_p[c].moveMenu()
s_p[c].apriMask()
c_subClip(s_p[c])
}
}
}
c_subClip(thisPath);
}


filexml=new XML();
file = file_xml_name+(no_cache ? "?rnd="+random(99999) : "");
filexml.load(file);
filexml.onLoad=parserXml;

//----------------------
// OPZIONI GENERALI
//----------------------

Obj=new Object();
Obj.disteso=allow;
Obj.inerlinea=interline;
Obj.rientro=tabulation;
Obj.velocita=velocity;
Obj.fontsize=fontsize;
Obj.distWfreccia=arrow_xposition;
Obj.distWtesto=text_xposition;
Obj.coloreTesto=text_color;
Obj.coloreTestoOver=text_color_over;
Obj.coloreLinea=parseInt(line_color);

//----------------------

function parserXml()
{
//------------------------------------- opzioni di colore x livello
var options = this.firstChild.attributes.colorliv;
Obj.mainOptions=options.split("|");
//-------------------------------------------------
nodes = this.firstChild.childNodes;
creaelementi(nodes);
delete (filexml);
delete (nodes);
}

//---------------------

function creaTextBox(pathClip, _testo_, _colore_, _overColore_, x)
{
var path;
var t=_testo_;
var a_t=t.split("\r\n");
t=a_t.join("");

NSurveyor
12/15/2005 11:34:38 PM
You know, it would help to post your code with comments (to explain what every
single function and maybe significant lines are doing) ALSO some XML sample
code to demonstrate how it is structured instead of just bumping your thread up.
AddThis Social Bookmark Button