6 Replies Latest reply on May 29, 2015 12:08 PM by sinious

    Flash Pro 1083:syntax error:package is unexpected

    jacquelynm24125526

      I am trying to write all my flash project code in a separate .as file for my data and navigation management. I keep getting this code and it always says the issue is on line 5 of my code even when I change the code and that line is blank. any ideas?

       

      package {

          public class us1pcas3testfile {

              var HomeBtn;

              HomeBtn.addEventListener(MouseEvent.CLICK, GoHome);

              function GoHome(event: MouseEvent): void {

                  MovieClip(this.root).gotoAndStop(1, "Main");

              }

              function HomeBtn();

              }

          }

      }

        • 2. Re: Flash Pro 1083:syntax error:package is unexpected
          Colin Holgate MVP & Adobe Community Professional

          You declare a variable without saying what it is. You're calling MovieClip without having the import line. There's also a function with the same name as the button. There's also no constructor function.

           

          This may be more correct:

           

          package  {

           

            import flash.display.MovieClip;

            import flash.display.SimpleButton;

            import flash.events.Event;

            import flash.events.MouseEvent;

           

            public class us1pcas3testfile {

           

            public var HomeBtn:SimpleButton;

           

            public function us1pcas3testfile() {

            addEventListener(Event.ADDED_TO_STAGE,added);

            }

           

            private function added(e:Event){

            removeEventListener(Event.ADDED_TO_STAGE,added);

            HomeBtn.addEventListener(MouseEvent.CLICK, GoHome);

            }

           

            private function GoHome(event: MouseEvent): void {

                      MovieClip(this.root).gotoAndStop(1, "Main");

                  }

           

           

            }

           

          }

          • 3. Re: Flash Pro 1083:syntax error:package is unexpected
            jacquelynm24125526 Level 1

            I tried this and it didn't work for what i was trying to do. I got past the syntax error by uninstalling and reinstalling Flash per the suggestion of Adobe customer service.  However I am still trying to figure out how to use my external file to make a button I reuse on multiple screens with the same instance name (HomeBtn) reuse the same function. I basically want a go back to beginning button for many of my screens. I still have some code in the .fla file for simple navigation.  I am very new to AS3 and can't find a good resource that explains the syntax and format to where it makes sense all together. Any suggestions is greatly appreciated. Some of the code you suggested I haven't seen in the tutorials and am having issues finding information to understand what it is doing.

            • 4. Re: Flash Pro 1083:syntax error:package is unexpected
              sinious Most Valuable Participant

              Can you explain exactly what you're trying to do, as much on-topic detail as possible. For example, should this button persist indefinitely or does it at any time disappear? Are you loading different scenes? Are you loading different SWF files into your current SWF?

               

              When you're in Flash, the very first FLA you run (test/debug) is the "parent" of everything. Everything else you do becomes a "child" of that parent. If you want something to be global, put it in the parent, or  be ready in each child to manage that object (MovieClip, etc). Since I'm presuming you're new, the easiest thing may just be to put this global button in the parent. Therefore anything else you load will not interfere with it. However if each child needs to place this button in different positions, etc, then there may be better ways to explain how to approach it.

               

              At this point we don't have enough information to guide you to the best answer so please share what the button needs to do and what is happening around it that might affect it.

              • 5. Re: Flash Pro 1083:syntax error:package is unexpected
                jacquelynm24125526 Level 1

                Ok, I will do my best to give as much detail as I can. I started with a new AIR for Android project with the intent of recreating my companies program automation for a support application/sales tool so I have images of screens in our program in the library and created a scene in the flash project for each one 18 total. I went through and tried creating navigation between scenes with invisible buttons over the image of where the actual buttons are on the automation. Most of these buttons are a 1 instance use. However there are many of the scenes that need to go back to the Main Scene frame 1. So I have made a HomeBtn that I have name on all the scenes and need to create a function for so that I don't need to retype the code 13 times.  After writing all my code on frame 1 of all the scenes I read that it is better to write all the code in an external .as file so I created a separate file for the code but have had nothing but hang ups since I started.  I want the button to persist when present on the scene. I have no idea what you mean about the SWF files because I'm still new to all this. All I have been working in is the .fla and the .as files.  Please let me know if you need more information.

                • 6. Re: Flash Pro 1083:syntax error:package is unexpected
                  sinious Most Valuable Participant

                  Anyone experienced in Flash (especially ActionScript) would first tell you to avoid using Scenes. They're often entirely misunderstood and they make people work in mysterious ways. What often isn't known is globals in scenes will collide because any code done in scene 1 will be on a merged timeline with scene 2/3/4/etc when it compiles.

                   

                  I know this isn't easy to understand so here's a really simple example of exactly what you're trying to do, albeit very simple:

                  http://www.ertp.com/tmp/SceneExample.zip

                   

                  In this example, "ActionScript" is placing an object from the FLA's library in the display. You can look in the library and open the properties of the single red box in there (acting as a button) and make sure you have advanced properties enabled. You will see the option to link for ActionScript is enabled and the linkage name is "myBtn". Now in frame 1 of Scene 1 you will see myBtn is added to the display list and a mouse event handler is added to it.

                   

                  After that the frame code uses setTimeout to delay running some code for 5 seconds. That code just selects "Scene 2" frame #1. On Scene 2 frame 1 there is just a stop();. The idea here is Scene 2 could represent any of your other scenes, and also, the red button still exists despite changing from Scene 1 to Scene 2. That covers your need for the same button in every scene. The buttons code is also retained. Any time you click the red button it will return back to Scene #1, frame 1, and the delay will happen again for 5 seconds, sending you right back to Scene 2 all over again. In a loop.

                   

                  Please examine this simple code for a means of adding a global button.

                  1 person found this helpful