简体   繁体   中英

AS3 Flash Stubborn Simple Button Not Appearing on Stage

I am using Flash Professional CS6/AS3 to make a simple game. I want a back button, that when clicked takes the player back to the intro screen. Everything else works, but the button will not show on the screen and it will not function when I drag it onto the screen and click it. The back_Btn class is empty and the symbol contains no timeline code.

There are no error messages. I want to reiterate that everything else is working perfectly.
Here's the document class:

package 
{
    import com.greensock.TweenLite;
    import com.greensock.*;
    import com.greensock.easing.*;
    import flash.display.MovieClip;
    import flash.events.Event;
    import flash.events.MouseEvent;
    import flash.display.Stage;
    import flash.display.SimpleButton;

    public class Main extends MovieClip
    {
        var back1:back_Btn;
        var intro:introScreen;
        var game:levelOne;
        var stageRef:Stage;
        //
        var timer:Number = 0;
        var holder:int = 0;
        var boolean:Boolean = false;
        var speed:int;
        //
        public function Main()
        {

            init();
        }
        function init():void
        {
            stageRef = stage;
            back1 = new back_Btn();
            stageRef.addChild(back1);
            //
            game = new levelOne();
            //
            intro = new introScreen();
            stageRef.addChild(intro);
            //
            back1.x = 425;
            back1.y = 0;
            intro.x = 0;
            intro.y = 0;

            intro.lampBtn.addEventListener(MouseEvent.CLICK,startGame);
            addEventListener(Event.ENTER_FRAME,startApp);
            back1.addEventListener(MouseEvent.CLICK,exitGame);

            speed = 0;

            function startApp(evt:Event):void
            {

                intro.x +=  speed;
                if ((boolean == true))
                {
                    speed = 5;
                    boolean = false;
                }

            }
        }
        function startGame(evt:Event):void
        {
            game = new levelOne  ;
            stageRef.addChild(game);
            game.x = 0;
            game.y = 0;
            boolean = true;
        }
        function exitGame(evt:Event):void
        {
            trace("back button clicked");
            removeChild(game);
            addChild(intro);
            intro.visible = true;
        }

    }
}

When not dragged onto the stage, the button doesn't appear. When dragged on, the trace statement doesn't fire when clicked and nothing happens. Very strange.

If your back_Btn is empty you cannot see it as there is nothing to see. Besides you addChild 'game' on top of back1. Intro is also on top.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM