Copy link to clipboard
Copied
Im tryign to make a back button in my program but it is not working
here is my code
I have to buttons on my movie clip called jupiterback and bb which are instances
Header 1 |
---|
public class Main extends MovieClip {
var hp:HomePage; var sp:StartPage; var sunP:SunPage ; var jupiterP:JupiterPage; var vx:Number; var vy:Number; var speed:int; var score:Number; var aship:Ship = new Ship(); var s1:Sun = new Sun(); var j1:Jupiter = new Jupiter (); public function Main() { sp = new StartPage(); hp = new HomePage(); sunP = new SunPage(); jupiterP = new JupiterPage(); vx = 0; vy = 0; score = 0;
addEventListener(KeyboardEvent.KEY_UP, onKeyUp); addEventListener(Event.ENTER_FRAME, onEnterFrameSun); addEventListener(Event.ENTER_FRAME, onEnterFrameJupiter);
// Start Page Event Listener sp.sb.addEventListener(MouseEvent.CLICK, onStartButtonClick); addEventListener(MouseEvent.CLICK, onStartButtonClick); stage.addEventListener(KeyboardEvent.KEY_DOWN, keyHit); addChild (sp);
jupiterP.bb.addEventListener(MouseEvent.CLICK, onBackButtonClickJupiter);
jupiterP.jupiterback.addEventListener(MouseEvent.CLICK, onBackButtonClickJupiter); addEventListener(MouseEvent.CLICK, onBackButtonClickJupiter); }
function onBackButtonClickJupiter(event:MouseEvent):void {
if (jupiterP != null && contains(jupiterP)) { removeChild(this.sp.homePage.jupiterP); addChild(hp); } // Ive tried this method too but doesnt work function onBackButtonClick_Jupiter(event:MouseEvent):void { addChild(hp); removeChild(jupiterP); } |
Copy link to clipboard
Copied
These are the errors it gives me
ArgumentError: Error #2025: The supplied DisplayObject must be a child of the caller.
at flash.display::DisplayObjectContainer/removeChild()
at Main/onEnterFrameJupiter()[Desktop\Main.as:229]
ArgumentError: Error #2025: The supplied DisplayObject must be a child of the caller.
Copy link to clipboard
Copied
I don't see where you ever addjupiterP as a child. If you don't add it, it cannot be removed.
Copy link to clipboard
Copied
i have a start page that has jupiterP inside it its called hp
when i click my startbutton hp opens up. I have a ship the ship moves to the planet jupiter and upon hitTest jupiterP opens up now i want to get back to hp using a button
function onStartButtonClick(event:MouseEvent): void
{
if (contains (sp))
{
removeChild(sp);
addChild(hp);
}
Copy link to clipboard
Copied
The jupiterP you test for in the code below is not the same jupiterP that lives somewhere inside sp
if (jupiterP != null && contains(jupiterP)) {
removeChild(this.sp.homePage.jupiterP);
addChild(hp);
}
Copy link to clipboard
Copied
What do I have to enter to find the instance of jupiterP inside sp ?
Copy link to clipboard
Copied
If i can do this I will be done does someone know how I can find that Instance ?
Copy link to clipboard
Copied
hello Mr Ned Murphy
Copy link to clipboard
Copied
Here's what I'd try based on what you showed...
if (sp.homePage.jupiterP != null && sp.homePage.contains(jupiterP)) {
sp.homePage.removeChild(sp.homePage.jupiterP);
addChild(hp);
}
and if you do not have an jupiterP instance being created for anything in that class, get rid of it from what you show in the class.
One other way to approach this might be to just make it invisible. That way you don't have to wonder so much about properly targeting it. It could reduce that entire conditional down to...
sp.homePage.jupiterP.visible = false;
addChild(hp);
Regarding your persistent follow-ups... I'm not complaining and am not trying to come off as angry... just realize I do not live in these forums, so you have to learn to be patient.
Copy link to clipboard
Copied
Sorry about the persistence i was desperate. Anyway i still couldnt get it to work so i took my game in a diffrent direction. Thanks
Find more inspiration, events, and resources on the new Adobe Community
Explore Now