WHAT'S NEW?
Loading...

Basic Three view As3

Basic Three view As3
Basic Three view As3

Ahirnya Setelah beberapa kali melakukan uji eksperiment akhirnya jadi juga threeview :p

<data>
<isi nama="Ricko">
<subisi nama="sub1">Lorep ipsum bla bla 1 Ricko</subisi>
<subisi nama="sub2">Lorep ipsum bla bla 2 RickoRickoRickoRicko</subisi>
<subisi nama="sub3">Lorep ipsum bla bla 3 RickoRickoRickoRickoRicko</subisi>
</isi>
<isi nama="Baba">
<subisi nama="sub1">Lorep ipsum bla bla 4 Baba</subisi>
</isi>
<isi nama="tesCuy">
<subisi nama="sub1">Lorep ipsum bla bla tesCuytesCuytesCuytesCuytesCuy</subisi>
</isi>
</data>

import flash.display.Sprite;
import com.PustakaFlash.*;
var xml:XML;
var n:int;
var subn:int;
var wd= new Sprite();
var cwd= new Sprite();
var gsr;
var mn;
var cdmn;
var posisiy:int;
var induk;
var ld:loadXml = new loadXml("threeviewAS3.xml");
ld.addEventListener(loadXml.COMPLETE, loadXmlCompleteHandler);
ld.addEventListener(loadXml.COMPLETE, loadXmlCompleteHandler);
ld.addEventListener(loadXml.ERROR, loadXmlErrorHandler);
ld.addEventListener(loadXml.SecurityError, loadXmlErrorHandler);
ld.addEventListener(loadXml.XML_ParseError, loadXmlErrorHandler);
function loadXmlCompleteHandler(e:Event):void
{
 xml = ld.data;
 n = xml.isi.length();
 trace(xml.isi.@nama);

 awal();

}
function loadXmlErrorHandler(e:Event):void
{
 switch (e.type)
 {
  case loadXml.ERROR :
   trace("file xml gak ketemu bos!!!");
   break;
  case loadXml.SecurityError :
   trace("SecurityError");
   break;
  case loadXml.XML_ParseError :
   trace("XML_ParseError");
   break;

 }
}


function awal()
{trace(n);
 for (var j:int = 0; j<n; j++)
 { mn= new menu();
  mn.x = 15;
  mn.y = j * (mn.height+5);
  mn.name = xml.isi. @ nama[j];
  mn.id = j;
  mn.data = j;
  mn.label.text = xml.isi. @ nama[j];
  addChild(wd);
  wd.addChild(mn);
  mn.buttonMode = true;
  mn.mouseChildren = false;
  mn.addEventListener(MouseEvent.CLICK, clickHandler);
 }
 garis.x=15;
 garis.y=(mn.height/2)+2;
 garis.height=(n*mn.height-5)+(subn*mn.height)-18;
}


function clickHandler(event:MouseEvent)
{ rmove();
 awal();
 trace(cwd);
 var gsr = event.currentTarget.id + 1;
 posisiy=((gsr-1) * (mn.height+5))+mn.height;
 trace((gsr-1) * (mn.height+5));
 trace(xml.isi[event.currentTarget.id ].subisi.@nama.length());
 subn = xml.isi[event.currentTarget.id].subisi. @ nama.length();
 trace(event.currentTarget.id)
 induk=event.currentTarget.id;
 garis.height=(n*mn.height-5)+(subn*mn.height)-15;
 geser(gsr);
 rmovechild();
 childawal(posisiy,subn);
}
function geser(gsr)
{
 for (var a:int = gsr; a<n; a++)
 {
  wd.getChildByName(xml.isi.@nama[a]).y += (subn*mn.height)+5;
 }

}
function rmove()
{
 while (wd.numChildren)
 {
  wd.removeChildAt(0);
 }
 removeChild(wd);
}
function rmovechild()
{
 while (cwd.numChildren)
 {
  cwd.removeChildAt(0);
 }
}
function childawal(posisiy:Number,subn:Number)
{
 for (var j:int = 0; j<subn; j++)
 {
  cdmn= new menu2();
  cdmn.x = 25;
  cdmn.y = j * (cdmn.height+5);
  cdmn.name = xml..subisi[j];
  cdmn.id = j;
  cdmn.data = xml..subisi[j];
  cdmn.label.text = xml..subisi. @ nama[j];
  if (cwd!=undefined)
  {
   addChild(cwd);
  }
  cwd.x = 25;
  cwd.y = posisiy;
  cwd.addChild(cdmn);
  cdmn.buttonMode = true;
  cdmn.mouseChildren = false;
  cdmn.addEventListener(MouseEvent.CLICK, info);
 }
}

function info(event:MouseEvent){
 textInfo.text=xml.isi[induk].subisi[event.currentTarget.id];
}