#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2011
    Posts
    3
    Rep Power
    0

    Menu Navigation AS3 - Class Document


    I am making a flash website for my girlfriend's art projects, and I have become a bit stumped. I've researched for a while and can't find the source of my problem. The website is all contained in a single flash file, each page is not it's own *.swf, and there are no compiler errors being displayed when tested.

    I'm trying to use an external *.as file to control all menu navigation, and when the movie is tested the first menu button clicked always works, however, once you try and go back to the original page or another new page it only works sometimes - it's like the buttons have lost their event listeners. Maybe someone with a bit more AS3 experience can tell me what is going on?

    Thank you.


    Code:
    package {
    	
    	import flash.display.MovieClip;
    	import flash.events.MouseEvent
    	
    	public class WebSite extends MovieClip {
    		
    		public function WebSite() {
    			stop();
    			
    			home_btn.addEventListener(MouseEvent.CLICK, GoToAndStop_home);
    			function GoToAndStop_home(event:MouseEvent):void
    			{
    				gotoAndStop("home");
    			}
    			
    			works_btn.addEventListener(MouseEvent.CLICK, GoToAndStop_works);
    			function GoToAndStop_works(event:MouseEvent):void
    			{
    				gotoAndStop("painting");
    			}
    			
    			bio_btn.addEventListener(MouseEvent.CLICK, GoToAndStop_bio);
    			function GoToAndStop_bio(event:MouseEvent):void
    			{
    				gotoAndStop("bio");
    			}
    			
    			contact_btn.addEventListener(MouseEvent.CLICK, GoToAndStop_contact);
    			function GoToAndStop_contact(event:MouseEvent):void
    			{
    				gotoAndStop("contact");
    			}
    			
    			init();
    		}
    		
    	}
    }
  2. #2
  3. No Profile Picture
    Gotta get to the next screen..
    Devshed Supreme Being (6500+ posts)

    Join Date
    Nov 2003
    Location
    Legion of Dynamic Discord
    Posts
    6,678
    Rep Power
    3164
    You should create the event handler functions outside of the WebSite function:
    Code:
    package
       {	
          import flash.display.MovieClip;
          import flash.events.MouseEvent
    
          public class WebSite extends MovieClip
             {
                public function WebSite()
                   {
                      stop();			
                      home_btn.addEventListener(MouseEvent.CLICK, GoToAndStop_home);							
                      // Other listeners go here.
                      init();
                   }
    
                function GoToAndStop_home(event:MouseEvent):void
                   {
                      gotoAndStop("home");
                   }
                   
                // Other event handler functions go here.
             }
       }
    Quis custodiet ipsos custodes?
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2011
    Posts
    3
    Rep Power
    0

    Thanks for the response


    That makes sense. However, when I try that the same problem exists. When I test the site with cmd + enter, the first button I click works fine and takes me to any page. After that it's spotty at best - most of the time none work after the first click, yet sometimes it will work once more but then stop working again.

    I did the first version with all timeline coding and no external .as file, and it works on 95% of computers, but it has the same problem of losing button functionality on others. The timeline coded site is uploaded to flythekite.com

    I was hoping it would solve the problem to have one external master code for the menu buttons, instead of coded in every page in the timeline which is messy - but my AS3 knowledge is fairly basic and I'm getting the same result.
  6. #4
  7. No Profile Picture
    Gotta get to the next screen..
    Devshed Supreme Being (6500+ posts)

    Join Date
    Nov 2003
    Location
    Legion of Dynamic Discord
    Posts
    6,678
    Rep Power
    3164
    Hi again, that seems to work for me in IE9. The HTML you're embedding it with is another story. Try using swfobject2 instead. They have full examples on their page. You could definitely be causing problems with that since the current code you're using is well outdated. One thing that jumps out at me straight away is that you're telling the Flash player that your content is meant for Flash Player 6 which is from years ago. I know for a fact that can't be correct since you are using AS3 which didn't exist back then.
    Quis custodiet ipsos custodes?
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2011
    Posts
    3
    Rep Power
    0
    Thank you, I will try those suggestions today. I really appreciate the feedback.

IMN logo majestic logo threadwatch logo seochat tools logo