Announcement

Collapse
No announcement yet.

My First Menu - gotoAndPlay not working

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    My First Menu - gotoAndPlay not working

    I'm sure I'm doing something wrong, but Scaleform tutorials and documentation is a nightmare of outdated code that seems to fail to compile or not work for other reasons. Honestly, the material is laughable.

    That said, this is what I'm trying to do:

    I have a menu with an Options button that is supposed to go to the Options Menu. You know, that first little "Hello World" script to get you excited.

    Everything compiles and seems like it should work, but the movie/scene doesn't go to the Options Menu and I have no idea why.

    I have my code in a .as file attached to the buttons of the menu converted to a symbol (only 1 for now).

    I based this off of one of the Scaleform AS3 Demo files and simply changed some references around, since their documentation is so far from the mark it's practically useless. (in fact, reverse engineering the demo files is what the admins have suggested for the past few years to do on the Scaleform forums, as they are aware of how outdated their documentation is). Heck, half of the written documentation is written in AS2 and the other half in AS3.

    Anywho, here is my code:

    
    Code:
    package scaleform
    {
        // Just a bunch of copied stuff from the original script - hopefully it is enough classes
        import flash.display.DisplayObject;
        import flash.display.MovieClip;
        import flash.events.Event;
        import flash.events.MouseEvent;
        import flash.text.TextFieldAutoSize;
            
        import scaleform.clik.core.UIComponent;
        import scaleform.clik.events.ButtonEvent;
        import scaleform.clik.constants.InvalidationType;
        import scaleform.clik.controls.Button;
        
            // Again, copied from the original script, but I changed the name to MainMenu and named the file MainMenu.as
        public class MainMenu extends UIComponent
        {
                // Button on the main menu has the instance name of optionsBtn, from the horrible tutorial - looked right to me, based on the original script
            public var optionsBtn:Button;
    
                // copied from the original script.  not sure why or if it is required, but it looked important
            public function MainMenu()
    	{
                super();
            }
            
                // based off the original script, seems to compile, and it is setup similarly to original
            override protected function configUI():void
    	{
                super.configUI();
                
                optionsBtn.addEventListener(ButtonEvent.CLICK, OpenOptionsScreen, false, 0, true);
            }
            
                // copied from the original script.  not sure why or if it is required, but it looked important
            override protected function draw():void
    	{
                super.draw();
            }
    	
                // I would suspect that this runs when I click the button, from what I've gathered, but nothing happens.  It just sits on the main menu.  What am I doing wrong here?
    	protected function OpenOptionsScreen(event:Event):void
    	{
    		gotoAndPlay("optionsScreen");
    	}
        }	
    }
    I'm using Flash Pro CS5.5, I've setup the scaleform launcher and added the AS3 CLIK directory to the AS3 preferences menu. The menu compiles and launches, but the button isn't doing what I hoped. Also, the keyframe for the Options Menu is named "optionsScreen".

    I am new to Action Script, but can read code fairly well and did my best to reverse engineer the demo code, but I'm sure there is some piece I'm missing.

    Any help would be appreciated. I feel if I can learn a bit more, I'll be able to make some real progress.

    Thanks!

    #2
    I guess more code might be needed to fully judge what's going on but for starters I don't see when and what calls the function configUI().
    Is there a call to it from some ADDED_TO_STAGE event listener of the parent class ?
    In other words, does your button have its CLICK event listener attached ?

    Comment


      #3
      Is the instance of the button on the flash-scene named "optionsBtn"? Flash can only link the variable: "public var optionsBtn:Button;" to the actual graphics object if it has the same name.

      (the main menu is the container that contains all the buttons, the button in the container needs to be named "optionsBtn")

      Otherwise I agree with above poster, put traces into the configUI and OpenOptionsScreen to see if it is called.

      I have my code in a .as file attached to the buttons of the menu converted to a symbol (only 1 for now).
      Also I don't understand this. The .as code has to be linked with the MainMenu, not with the buttons. Go to the mainmenu library-object and enter the path to the .as code file into the "base class" field.

      Comment


        #4
        Originally posted by limscafo View Post
        Is the instance of the button on the flash-scene named "optionsBtn"? Flash can only link the variable: "public var optionsBtn:Button;" to the actual graphics object if it has the same name.

        (the main menu is the container that contains all the buttons, the button in the container needs to be named "optionsBtn")

        Otherwise I agree with above poster, put traces into the configUI and OpenOptionsScreen to see if it is called.



        Also I don't understand this. The .as code has to be linked with the MainMenu, not with the buttons. Go to the mainmenu library-object and enter the path to the .as code file into the "base class" field.
        I wish I knew more about the parent class. I'll have to look at it. I just tried to do it the same way the demos were setup. All of the code was provided by the developers. The button is one of the pre-made components from Scaleform, and I added my event listener in the same way they did (which works).

        The way I setup the menu is thusly: I created a Symbol called "MainMenu", which has the AS code attached to it under Base Class as "scaleform.MainMenu", and comes back good when I use the Validate Base Class Definition button. Within that symbol is the instance of symbol used as the options button, called "MainMenuButton". The Instance Name for the options button that's symbol name is "MainMenuButton" is indeed "optionsBtn." I'll try and run a trace as suggested, once I go through some help and figure out how. I did it that way so I only have one code file for all of the buttons of the main menu I'll eventually have. I'll simply add instances of "MainMenuButton" to "MainMenu" and add code. It seemed like a good idea to me, as that is how it was done in the demo files.

        I hope that makes sense

        My terminology is probably a little off.

        Comment


          #5
          I ran the traces, and they worked. They returned some text to this cmd window when the video started "ConfigUI" function, and when I press the Options Button, I get "OpenOptionsScreen".

          At least that confirm the process flow is correct. I have no idea why the movie isn't going to the Options Screen

          Does the Gotoandplay function not know I want to apply it to the Scene? I'm pretty new to AS, and I might be running into scope issues.

          Comment


            #6
            I figured it out. It was a scope issue.

            Since the AS is attached to as Symbol, I have to figure out how to run the function on the Scene root. In AS2, you simply use _root.function();

            In AS3, you have to create a variable:

            public var locRoot = root;

            Then use it thusly:

            locRoot.gotoAndPlay("optionsScreen");

            And it worked!!! I'm really happy, and thanks for telling me about the trace function. I was also wondering if I had done it correctly, since I am using so much code from others.

            I hope this helps others. AS3 is not too bad once you get a few of the little nuances down. I'm sure I'll be back with more questions, but this helps a ton.

            Comment

            Working...
            X