ok, so i’ve been procedural programming with AS2 for a few years. just recently jumped into AS3 a couple of weeks ago and working on a current project and trying to write a class that:
- loads and collects data from an XML file
- creates text-based buttons using the XML data
- loads page sections once these buttons are clicked
i have all those down so far.
but i can’t for the life of me figure out how to target the sections that were loaded. (deleting it/tweening it out when another section loads) i’ve been hacking for like 4 hours and i can’t figure it out. please help! i’ll design you a logo!
i am using TweenMax for tweening. there are two for loops that create the text buttons because they are separated with a header. if there is an easier way to do this, please let me know. the section class is a library movieclip and populated with data from the XML file. it is loaded to what i think is the parent clip of the buttom. so, each instance should look like:
[container]
__<textcontainer>
____[text]
__<loaded section clip> <— i want to be able to remove this when another container clip is clicked…
here is my code (warning this is probably pretty ugly, if you can spot any suggestions, please do tell):
private var currentSection:String;
private function navClick(evt:MouseEvent)
{
currentSection = evt.target.section + evt.target.instance;
loadSection(evt.target.section, evt.target.instance);
//var workPage:WorkPage = new WorkPage();
//workPage.x = 245;
//workPage.y = 146;
//workPage.worktitle.text = navData.pieces[evt.target.section].work.sectiontitle[evt.target.instance];
//MovieClip(root).addChild(workPage);
}
private var aSectionLoaded:Boolean = false;
private function loadSection(section:String, instance:String){
if (aSectionLoaded == true){
//removeChildAt();
}
trace(section);
trace(instance);
var workPage:WorkPage = new WorkPage();
workPage.x = 245;
workPage.y = 146;
workPage.worktitle.text = navData.pieces[section].work.sectiontitle[instance];
MovieClip(root).addChild(workPage);
aSectionLoaded = true;
workPage.addEventListener(MouseEvent.CLICK, traceThis);
}
private function traceThis(evt:MouseEvent)
{
trace(evt.currentTarget);
trace(getChildIndex(DisplayObject(root)));
}
}
}