Reputation: 35
Im trying to make a menu but my movieclip doesn't appear on stage. I tested it with a trace and it does start running when 'addChild(currentClip) get executed.
It's objected oriented programming, so i added my whole class. Sorry for the comments, else i get lost :)
package
{
import flash.display.MovieClip;
import flash.events.EventDispatcher;
import flash.events.MouseEvent;
import flash.events.Event;
public class IntroClip extends MovieClip
{
var currentClip:MovieClip;
public static const MY_FINISHED_INTRO_CLIP_EVENT:String = "my_finished_intro_clip_event";
// constructor code
public function IntroClip()
{
startButton.addEventListener(MouseEvent.CLICK, openMainGame);
howToButton.addEventListener(MouseEvent.CLICK, openHowTo);
hiscoreButton.addEventListener(MouseEvent.CLICK, openHiscore);
}
//Open het spel
public function openMainGame (event:MouseEvent):void
{
//Bij klikken IntroClip verwijderen en MainGame toevoegen
dispatchEvent(new Event(MY_FINISHED_INTRO_CLIP_EVENT));
currentClip = new MainClip();
trace('addChild')
addChild(currentClip);
currentClip.x=160;
currentClip.y=160;
}
//Open de opties
public function openHowTo (event:MouseEvent):void
{
//Bij klikken IntroClip verwijderen en Options toevoegen
dispatchEvent(new Event(MY_FINISHED_INTRO_CLIP_EVENT));
}
//Open de hiscores
public function openHiscore (event:MouseEvent):void
{
//Bij klikken IntroClip verwijderen en Hiscores toevoegen
dispatchEvent(new Event(MY_FINISHED_INTRO_CLIP_EVENT));
}
}
}
Upvotes: 1
Views: 512
Reputation: 446
In your main class, Kikkers, method startMainGame, you are removing the currentClip and not re-adding it to stage. The problem is that you add the MainClip in the openMainGame method of the IntroClip instead of adding it in the main class, Kikkers. You should modify startMainGame in Kikkers like this:
public function startMainGame( event: Event): void
{
trace("Start Main Game");
currentClip.removeEventListener(IntroClip.MY_FINISHED_INTRO_CLIP_EVENT, startMainGame);
removeChild(currentClip);
currentClip = new MainClip();
currentClip.x = 160;
currentClip.y = 160;
addChild(currentClip);
}
In openMainGame method in IntroClip, you should only keep the first line that dispatches the event.
Upvotes: 1
Reputation: 2129
You can't see anything because the MainClip does not have any graphics. Try
public function MainClip()
{
this.graphics.beginFill(0xF244A7);
this.graphics.drawCircle(20,20, 100);
this.graphics.endFill();
}
and when you add it to the stage, you should be able to see something :)
Upvotes: 0