Add/remove parent, child objects. help needed
i'm working on interactive map client. i'm stuck on functionality.
it's has 3 locations (child1-3) on base map(bg), each stands link assigned popup boxes.
child2 , child3 shares same mag object shows additional 5 locations.
i've done showing base bg , 3 initial locations. tried show first popup box clicking child1 , has success.
but further i'm having problem removing box1 , it's boxx button means want return main_mc state removing objects.
**pls me on work i'll appreciate valuable time helping me. i'm open send bonus via skrill or paypal.
main_mc (parent)+
|
|___bg
|
|
|___child1+
| |___ box1
|
|___child2+
| |
| | |__box2
| | |__box3
| |___mag+___|__box4
| | |__box5
| | |__box6
| |
| |
| |
|___child3+
here toddler looking code started.
package{
import flash.display.sprite;
import flash.display.displayobject;
import flash.events.mouseevent;
import flash.net.urlrequest;
import flash.events.event;
public class main extends sprite{
private var bg:sprite;
private var child1:sprite;
private var child2:sprite;
private var child3:sprite;
public function main(){
var bg:sprite = new bginstance();
bg.x=360;
bg.y=212;
bg.name="bgmap"
addchild(bg);
child1 = new child1instance();
child1.buttonmode = true;
child1.x=479;
child1.y=132;
child1.name="child1name";
child1.addeventlistener(mouseevent.click, showbox);
addchild(child1);
child2 = new child2instance();
child2.buttonmode = true;
child2.x=463;
child2.y=282;
child2.name="child2name";
child2.addeventlistener(mouseevent.click, showmag);
addchild(child2);
child3 = new child3instance();
child3.buttonmode = true;
child3.x=389;
child3.y=335;
child3.name="child3name";
addchild(child3);
} //closing brace function main
//handler
private function showbox (e:mouseevent):void{
var box1:sprite;
box1=new box1instance();
box1.x=-279;
box1.y=-32;
box1.name = "box1name";
var boxx:sprite;
boxx=new boxxinstance();
boxx.x=-159;
boxx.y=-79;
boxx.name="boxxname";
buttonmode = true;
child1.addchild(box1);
child1.addchild(boxx);
trace(child1.numchildren); //it returns 3 instead of 2 ?
trace(box1.numchildren); //it returns 3 instead of 0 ?
boxx.addeventlistener(mouseevent.click, boxxhandler);
} //closing brace function showbox
//function removing showbox
private function boxxhandler(evt:mouseevent):void {
child1.removechildat(0); // removes child1 on first click?
}//closing brace function boxxhandler
//function managing showmag
private function showmag (e:mouseevent):void{
var magbox:sprite;
magbox=new maginstance();
magbox.x=-275;
magbox.y=-95;
magbox.name="magboxname";
var magboxx:sprite;
magboxx=new magxinstance();
buttonmode = true;
magboxx.x=-145;
magboxx.y=-190;
magboxx.name="magboxxname";
child2.addchild(magbox);
child2.addchild(magboxx);
trace(child2.getchildat(0).name);
magboxx.addeventlistener(mouseevent.click, magboxxhandler);
} //closing brace function showmag
private function magboxxhandler(evt:mouseevent):void {
}
} //closing brace class main
} //closing brace package
if want target dynamically created box1 , boxx instances can use getchildbyname that...
child1.removechild(child1.getchildbyname("box1name"));
child1.removechild(child1.getchildbyname("boxxname"));
More discussions in ActionScript 3
adobe
Comments
Post a Comment