A Flash Developer Resource Site

Results 1 to 13 of 13

Thread: Menu buttons "scrolling" in wrong order

  1. #1
    Member
    Join Date
    Mar 2008
    Posts
    30

    Menu buttons "scrolling" in wrong order

    I've created a list menu by placing Button symbols in a vertical row, for the user to be able to go through them with the up/down keys (each keypress highlighting the next button). However, sometimes they are highlighted in the wrong order, ie if I'm on menu item no 3 and press down, I might go to item no 5. When going upwards the "skips" are different, but in both directions always consistent.

    The buttons are all of the same size, but obviously have different amounts of text on them. I've tried tracking them as both Menu Items and Buttons, but it doesn't seem to make any difference.

    Thanks in advance for all help!

  2. #2
    Registered User
    Join Date
    Apr 2001
    Location
    Akron OH, USA
    Posts
    4,841
    normally developers do not rely upon flash's tab order to control focus.

    Instead developers tend to create an off screen button to trap events and then change the appearance of on screen elements (not buttons but movie clips or graphics) to show focus.

  3. #3
    Member
    Join Date
    Mar 2008
    Posts
    30
    Thanks for your answer, sounds reasonable. However, since I'm just starting out and am stuck with a very limited deadline for this application, I'll just go with the easier (?) focus tabbing.

    Found a way to control it btw:

    myfirstbutton.tabIndex = 1;
    mysecondbutton.tabIndex = 2;

    This ensures the tabbing order.

    EDIT: Or so I thought... might not be a working solution after all Apparently, tabIndex is not supported on units with 4-way navigation.

    But still, there must be some sort of logic as to what tabbing order Flash Lite uses?
    Last edited by squallsquall; 03-14-2008 at 10:15 AM.

  4. #4
    Registered User
    Join Date
    Apr 2001
    Location
    Akron OH, USA
    Posts
    4,841
    how are you ordering your buttons, vertical, horizontal or table? are they all in the same movie clip?
    what version of Flash lite are you using?

  5. #5
    Member
    Join Date
    Mar 2008
    Posts
    30
    They're ordered in a vertical column. I've tried spacing them out a little further (they're pretty close to each other), but it didn't seem to help.

    Currently I'm not using any movie clips at all, the buttons are all directly on "scene 1". Is this the wrong way to do it?

    I'm using Flash Prof CS3 and Lite 2.0.

    Thanks for taking the time to help me in this! I'm just starting out, so I'm having trouble with a few things as you can tell.

    EDIT: Another wierd observation: If I push to the right a couple of times at some place in the menu (sometimes shifts the focus up or down a slot or two, depending on where focus is), the menu seems to scroll correctly after that. Strange...
    Last edited by squallsquall; 03-17-2008 at 04:55 AM.

  6. #6
    Member
    Join Date
    Mar 2008
    Posts
    30
    I've tried a different approach now, more like the one you suggested. There, I have one keyframe for each button (although now they're only images) focus, with a corresponding ActionsScript looking like this:


    var myListener:Object = new Object();
    myListener.onKeyDown = function() {
    if (Key.getCode() == Key.LEFT) {
    gotoAndStop(2);
    } else if (Key.getCode() == Key.RIGHT) {
    gotoAndStop(4);
    } else if (Key.getCode() == Key.UP) {
    gotoAndStop(9);
    } else if (Key.getCode() == Key.DOWN) {
    gotoAndStop(6);
    }
    };
    Key.addListener(myListener);


    However, it behaves strange as well, with seemingly random movements even though I have double checked the numbers. Also, sometimes it becomes sluggish after a while and even freezes Flash. Is it a problem that listeners on different frames are added with the same namne, or that when I return to a fram, the same listener is added again?

  7. #7
    Registered User
    Join Date
    Apr 2001
    Location
    Akron OH, USA
    Posts
    4,841
    you only need to declare the key listener once, probably best in frame 1.

    by the way you may find a switch/case statement more friendly for this sort of thing.

    switch(Key.getCode()){
    case key.LEFT: gotoAndStop(2); break;
    case key.RIGHT: gotoAndStop(4); break;
    case key.UP: gotoAndStop(9); break;
    case key.DOWN: gotoAndStop(6); break;
    }

  8. #8
    Member
    Join Date
    Mar 2008
    Posts
    30
    Yeah, figured all the declarations were the cause of the error. Current design is like this.

    Frame1:

    var myListener:Object = new Object();
    Key.addListener(myListener);
    gotoAndStop(6);

    Frames 2-10 each similar to this (but with "their own" numbers):

    myListener.onKeyDown = function() {
    if (Key.getCode() == Key.LEFT) {
    gotoAndStop(4);
    } else if (Key.getCode() == Key.RIGHT) {
    gotoAndStop(6);
    } else if (Key.getCode() == Key.UP) {
    gotoAndStop(2);
    } else if (Key.getCode() == Key.DOWN) {
    gotoAndStop(8);
    }
    };

    Is that the correct way to first declare and then have a unique function for each state?

    The funny this now is that navigation works like a charm as long as the gotoAndStop() directs to frames 2-5. If it directs to 6 it still goes to frame 5 but then works, and if it directs to 6-10 the application does not respond to key presses at all (although Flash itself does not crash). I guess it's kind of hard for you to find the cause through this forum, though... the thing is I've checked each frame and their actionscript is built the exact same way (except for the numbers).

    EDIT: Will try out the Switch/Case, although I suspect you meant it more as an easier way of coding than actual bug-fix.

  9. #9
    Member
    Join Date
    Mar 2008
    Posts
    30
    Hm, trying to upload the actual fla-file now, if it helps...

    Thanks for your patience!
    Attached Files Attached Files

  10. #10
    Registered User
    Join Date
    Apr 2001
    Location
    Akron OH, USA
    Posts
    4,841
    you only need to set up the code for all key events once. You do not need one in each frame. The switch/case is not a bug fix but an easier code to use.

  11. #11
    Member
    Join Date
    Mar 2008
    Posts
    30
    I thought of that as well, my problem is that the buttons' action depend on which frame the application is currently on (for example, if on frame 5 "UP" might mean gotoAndStop(2), but if on frame 9 the same "UP" keypress should trigger gotoAndStop(5)). When declaring the function for the keys only once, I guess it needs to be more dynamic. Is there a way to check which frame the application is currently on (I searched for such a feature, but didn't find any), or do you recommend another way of solving this?

    Thanks again!

  12. #12
    Registered User
    Join Date
    Apr 2001
    Location
    Akron OH, USA
    Posts
    4,841
    Eventhough it requires more typing and longer code, it may be easier to manage the logic for this if you put all the code into functions and events in the first frame.

    You can get the current frame with the _currentframe property.

    I would probably create an event handler function for each type of button event.

    Code:
    // function to process "up" key presses depending upon current frame
    function onUpKeyPress(){
       switch(_currentframe){
          case 2: gotoAndStop(?); break; // move to appropriate frame
          case x: gotoAndStop(?); break; // move to appropriate frame
       }
    }
    
    // listener code to trap key down events and assign them to functions
    myListener.onKeyDown = function() {
       switch(Key.getCode()){
          case Key.UP: onUpKeyPress(); break;
          case Key.DOWN: onDownKeyPress(); break;
       }
    }

  13. #13
    Member
    Join Date
    Mar 2008
    Posts
    30
    Wow, everything works like a charm now!

    Thanks a lot for your help hp3, I really appreciate it.

Posting Permissions

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




Click Here to Expand Forum to Full Width

HTML5 Development Center