AS3 Keep Track of Where FocusRect Is Whilst Tabbing


/ Published in: ActionScript 3
Save to your folder(s)

This code traces out the name (and display list path) of the object that currently has focus. This handy when you are testing the tab order and you can't see a yellow rectangle anywhere.


Copy this code and paste it in your HTML
  1. import flash.events.FocusEvent;
  2.  
  3. stage.addEventListener(FocusEvent.FOCUS_IN, onStage_FOCUS_IN);
  4.  
  5. function onStage_FOCUS_IN(event:FocusEvent):void
  6. {
  7. focusInPath(DisplayObject(event.target));
  8. }
  9.  
  10. function focusInPath(dispObj : DisplayObject, s : String = ""):void
  11. {
  12. if (dispObj.parent != null) {
  13. focusInPath(dispObj.parent, s + "." + dispObj.name);
  14. } else {
  15. var a:Array = s.split(".").reverse();
  16. var output:String = "";
  17. for (var i : Number = 0; i < a.length; i++) {
  18. output = output + "." + a[i];
  19. }
  20. trace("FOCUS_IN: " + output.substr(1, output.length - 2));
  21. }
  22. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.