SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Member
    Join Date
    Dec 2008
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question question: how to keep the button symbol in the "hit" state?

    I am a new Flash user (CS3) building my first Web site with it. This should be simple and maybe it is. But I don't know how to keep the button symbol in the "hit" state once the user has clicked on it and the page (frame) has loaded. I want the user to see what page he is on by the link being in the "hit" state. Now once the page has loaded the link just reverts back to its "up" state.

    Do I have to add action script for this and on what frame (inside the button symbol or in the main timeline)?

    Thanks for your wisdom...

    psquared

  2. #2
    SitePoint Addict
    Join Date
    Jul 2005
    Location
    USA
    Posts
    291
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i'm not sure if that's possible with a symbol being tracked as a button. i normally use movieclips and add event listeners for mouse events. then have different frame labels for up/over/down/disabled states and handle display that way. you could then assign a "selected" property that would ignore mouse events at certain times.

  3. #3
    SitePoint Member
    Join Date
    Dec 2008
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks, an00bis--

    You wrote:
    you could then assign a "selected" property that would ignore mouse events at certain times.

    Can you give me an example of action script that assigns a selected property for this? I'm working through lynda.com tutorials to figure this stuff out but my action script abilities are very weak at this point.

    psquared

  4. #4
    SitePoint Addict
    Join Date
    Jul 2005
    Location
    USA
    Posts
    291
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    if you had a menu controller that set the selected value of your buttons, you could use something like this

    Code:
    package
    {
    	import flash.display.MovieClip;
    	import flash.events.Event;
    	import flash.events.MouseEvent;
    	
    	/**
    	 * SampleButton class
    	 */
    	public class SampleButton extends MovieClip
    	{
    		private var __selected:Boolean;
    		
    		/**
    		 * SampleButton constructor
    		 */
    		public function SampleButton()
    		{
    			buttonMode = true;
    			useHandCursor = true;
    			
    			addEventListener(MouseEvent.MOUSE_OVER, mouseOverHandler);
    			addEventListener(MouseEvent.MOUSE_OUT, mouseOutHandler);
    			addEventListener(MouseEvent.CLICK, clickHandler);
    		}
    		
    		/**
    		 * @param event
    		 */
    		private function mouseOverHandler(event:MouseEvent = null):void
    		{
    			gotoAndStop("over");
    		}
    		
    		/**
    		 * @param event
    		 */
    		private function mouseOutHandler(event:MouseEvent = null):void
    		{
    			if (!__selected) {
    				gotoAndStop("up");
    			}	
    		}
    		
    		/**
    		 * @param event
    		 */
    		private function clickHandler(event:MouseEvent = null):void
    		{
    			if (!__selected) {
    				// Handle click event
    			}	
    		}
    		
    		/**
    		 * Getter and setter for selected property
    		 */
    		public function get selected():Boolean {
    			return __selected;
    		}
    		public function set selected(value:Boolean):void {
    			__selected = value;
    			if (value) {
    				mouseOverHandler();
    			} else {
    				mouseOutHandler();
    			}
    		}
    	}
    }
    the sample above assumes you have two states (over, up) and frame labels for those states. the __selected property will determine if the button stays highlighted or not.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •